Editing User:Clouddrift/GSoC2014/Midterm

From BRL-CAD

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 1: Line 1:
 
== Reorganize NMG Data Structure ==
 
== Reorganize NMG Data Structure ==
  
The functionality of struct '''model''' and '''nmgregion''' are top two level of old nmg structure. One '''model''' can include multiple '''nmgregion''', and one '''nmgregion''' can include multiple '''shell'''. We can have a brief view at following class definition.
 
  
<pre>
+
== Fix Debugs ==
struct model
 
{
 
    uint32_t magic;
 
    struct bu_list r_hd; /**< @brief list of regions */
 
    char *manifolds;            /**< @brief structure 1-3manifold table */
 
    long index; /**< @brief struct # in this model */
 
    long maxindex; /**< @brief # of structs so far */
 
};
 
</pre>
 
  
<pre>
+
Due to the change of core NMG data structure, thousands of compiling errors are coming. I spend most time in these weeks to fix and test them. The statistics is as following:
struct nmgregion {
 
    struct bu_list l; /**< @brief regions, in model's r_hd list */
 
    struct model *m_p; /**< @brief owning model */
 
    struct nmgregion_a *ra_p; /**< @brief attributes */
 
    struct bu_list s_hd; /**< @brief list of shells in region */
 
    long index; /**< @brief struct # in this model */
 
};
 
</pre>
 
  
In general, it's a classical representation for NMG structure. But they are  redundant in BRL-CAD. There have been similar concepts here called '''combination''' which can hold several primitives as a whole. So some reorganization is necessary that these two structs ('''model''' and '''nmgregion''') are replaced by the BRL-CAD inner '''combination''' to fit new NMG philosophy.
+
* RT_EXPORT extern struct model *nmg_mmr(void);
 
+
* RT_EXPORT extern struct nmgregion *nmg_mrsv(struct model *m);
To achieve this target, we should move some important members from '''model''' and '''nmgregion''' to new '''shell''' to keep existing function, then take the new '''shell''' as the top level of new NMG structure. Details as following:
+
* RT_EXPORT extern int nmg_kr(struct nmgregion *r);
 
+
* RT_EXPORT extern void nmg_km(struct model *m);
* '''char *manifolds''': Describe the meaning of a NMG structure.
+
* RT_EXPORT extern void nmg_region_a(struct nmgregion *r, const struct bn_tol *tol);
* '''long maxindex''': Record the element(nmg structure of various levels) count of a NMG structure. It is important in MAKE and IMPORT/EXPORT part such as deciding how big memory should be allocated.
+
* RT_EXPORT extern struct model *nmg_find_model(const uint32_t *magic_p);
 
+
* RT_EXPORT extern struct vertex *nmg_find_pt_in_model(const struct model *m,
Then, let's check the definition of old '''shell''':
+
    const point_t pt,
 
+
    const struct bn_tol *tol);
<pre>
+
* RT_EXPORT extern void nmg_pr_m(const struct model *m);
struct shell {
+
* RT_EXPORT extern void nmg_pr_r(const struct nmgregion *r,
    struct bu_list l; /**< @brief shells, in region's s_hd list */
+
      char *h);
    struct nmgregion *r_p; /**< @brief owning region */
+
* RT_EXPORT extern int nmg_find_outer_and_void_shells(struct nmgregion *r,
    struct shell_a *sa_p; /**< @brief attribs */
+
    struct bu_ptbl ***shells,
    struct bu_list fu_hd; /**< @brief list of face uses in shell */
+
    const struct bn_tol *tol);
    struct bu_list lu_hd; /**< @brief wire loopuses (edge groups) */
+
* RT_EXPORT extern fastf_t nmg_region_area(const struct nmgregion *r);
    struct bu_list eu_hd; /**< @brief wire list (shell has wires) */
+
* RT_EXPORT extern fastf_t nmg_model_area(const struct model *m);
    struct vertexuse *vu_p; /**< @brief internal ptr to single vertexuse */
+
* RT_EXPORT extern struct model *nmg_mk_model_from_region(struct nmgregion *r,
    long index; /**< @brief struct # in this model */
+
int reindex);
};
+
* RT_EXPORT extern int nmg_mv_shell_to_region(struct shell *s,
</pre>
+
    struct nmgregion *r);
 
+
* RT_EXPORT extern char *nmg_manifolds(struct model *m);
Obviously, some members should be changed to achieve new NMG philosophy:
+
* RT_EXPORT extern void nmg_r_to_vlist(struct bu_list *vhead,
* '''struct nmgregion *r_p''': Can be removed since there is no '''nmgregion''' concept any more.
+
    const struct nmgregion *r,
* '''struct bu_list l''': We don't need this backward point which points to '''shell''' 'superior level structure. But a new member '''uint32_t magic''' is still necessary.
+
    int poly_markers);
 
+
* RT_EXPORT extern void nmg_m_to_vlist(struct bu_list *vhead,
Following is the new '''shell''' definition after reorganization.
+
    struct model *m,
 
+
    int poly_markers);
<pre>
+
* RT_EXPORT extern void nmg_pl_r(FILE *fp,
struct shell {
+
      const struct nmgregion *r);
    uint32_t magic;
+
* RT_EXPORT extern void nmg_pl_m(FILE *fp,
    struct shell_a *sa_p; /**< @brief attribs */
+
      const struct model *m);
    struct bu_list fu_hd; /**< @brief list of face uses in shell */
+
* RT_EXPORT extern void nmg_vlblock_r(struct bn_vlblock *vbp,
    struct bu_list lu_hd; /**< @brief wire loopuses (edge groups) */
+
    const struct nmgregion *r,
    struct bu_list eu_hd; /**< @brief wire list (shell has wires) */
+
    int fancy);
    struct vertexuse *vu_p; /**< @brief internal ptr to single vertexuse */
+
* RT_EXPORT extern void nmg_vlblock_m(struct bn_vlblock *vbp,
    char *manifolds; /**< @brief structure 1-3manifold table */
+
    const struct model *m,
    long index; /**< @brief struct # in this model */
+
    int fancy);
    long maxindex; /**< @brief # of structs so far */
+
* RT_EXPORT extern void nmg_vshell(const struct bu_list *hp,
};
+
const struct nmgregion *r);
</pre>
+
* RT_EXPORT extern void nmg_vregion(const struct bu_list *hp,
 
+
  const struct model *m);
== Fit New NMG Data Structure ==
+
* RT_EXPORT extern void nmg_vmodel(const struct model *m);
 
+
* RT_EXPORT extern int nmg_ck_closed_region(const struct nmgregion *r,
Changing the NMG data structure is just first step. Due to these change, thousands of compiling errors are coming. I spent most of my time in these weeks to fix and test them properly.
+
  const struct bn_tol *tol);
 
+
* RT_EXPORT extern void nmg_r_radial_check(const struct nmgregion *r,
It worth mentioning that 28 functions in raytrace.h are removed which may simplify the future work because they are no longer useful. The detailed list is as following:
+
const struct bn_tol *tol);
 
+
* RT_EXPORT extern void nmg_visit_region(struct nmgregion *r,
* struct model *'''nmg_mmr'''(void);
+
      const struct nmg_visit_handlers *htab,
* struct nmgregion *'''nmg_mrsv'''(struct model *m);
+
      genptr_t state);
* int '''nmg_kr'''(struct nmgregion *r);
+
* RT_EXPORT extern void nmg_visit_model(struct model *model,
* void '''nmg_km'''(struct model *m);
+
      const struct nmg_visit_handlers *htab,
* void '''nmg_region_a'''(struct nmgregion *r, const struct bn_tol *tol);
+
      genptr_t state);
* struct model *'''nmg_find_model'''(const uint32_t *magic_p);
 
* struct vertex *'''nmg_find_pt_in_model'''(const struct model *m, point_t pt, struct bn_tol *tol);
 
* void '''nmg_pr_m'''(const struct model *m);
 
* void '''nmg_pr_r'''(const struct nmgregion *r, *h);
 
* int '''nmg_find_outer_and_void_shells'''(struct nmgregion *r, bu_ptbl ***shells, struct bn_tol *tol);
 
* fastf_t '''nmg_region_area'''(const struct nmgregion *r);
 
* fastf_t '''nmg_model_area'''(const struct model *m);
 
* struct model *'''nmg_mk_model_from_region'''(struct nmgregion *r, reindex);
 
* int '''nmg_mv_shell_to_region'''(struct shell *s, nmgregion *r);
 
* char *'''nmg_manifolds'''(struct model *m);
 
* void '''nmg_r_to_vlist'''(struct bu_list *vhead, struct nmgregion *r, int poly_markers);
 
* void '''nmg_m_to_vlist'''(struct bu_list *vhead, struct model *m, int poly_markers);
 
* void '''nmg_pl_r'''(FILE *fp, const struct nmgregion *r);
 
* void '''nmg_pl_m'''(FILE *fp, const struct model *m);
 
* void '''nmg_vlblock_r'''(struct bn_vlblock *vbp, const struct nmgregion *r, int fancy);
 
* void '''nmg_vlblock_m'''(struct bn_vlblock *vbp, const struct model *m, int fancy);
 
* void '''nmg_vshell'''(const struct bu_list *hp, const struct nmgregion *r);
 
* void '''nmg_vregion'''(const struct bu_list *hp, const struct model *m);
 
* void '''nmg_vmodel'''(const struct model *m);
 
* int '''nmg_ck_closed_region'''(const struct nmgregion *r, const struct bn_tol *tol);
 
* void '''nmg_r_radial_check'''(const struct nmgregion *r, const struct bn_tol *tol);
 
* void '''nmg_visit_region'''(struct nmgregion *r, const struct nmg_visit_handlers *htab, genptr_t state);
 
* void '''nmg_visit_model'''(struct model *model, const struct nmg_visit_handlers *htab, genptr_t state);
 
 
 
After that, there is no shortcut but to check the compiling errors one by one. Read the codes, understand the context and fix them to fit new nmg structure. It's a bit tedious but helpful for getting familiar with this part of BRL-CAD further more. There are some main kinds of situation:
 
* Change a function of '''model/nmgregion''' version to a '''shell''' version.
 
* Extend existing function to support new members of '''shell'''.
 
* Remove the traversal of '''model/nmgregion'''. Fortunately, some function assume only one '''shell''' in the '''model'''.
 
  
 
== Conclusion ==
 
== Conclusion ==
 
At first, I'd like to extend my heartfelt gratitude to my mentor, Daniel and other developers in BRL-CAD community. I was so excited to learn plenty of knowledge and skills which cannot be gained in other places.
 
 
I am sorry that my progress falls a little bit behind compared with my initial proposal because some mistake make me go into a wrong way especially when I fix the functionality about Import/export modules. It takes me some time to figure out what happens exactly to MGED when user use 'facetize -n' command and to find out the most proper solution. In next weeks, I will speed up to catch up with the schedule and try my best to finish the project as what I promised.
 
 
As for the code statistics, the result from statSVN shows 303 places in my branch have been changed. The count of code lines been changed is 3608.
 

Please note that all contributions to BRL-CAD may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see BRL-CAD:Copyrights for details). Do not submit copyrighted work without permission!

To edit this page, please answer the question that appears below (more info):

Cancel Editing help (opens in new window)