Blender V2.61 - r43446

reeb.h

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version. 
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * Contributor(s): Martin Poirier
00019  *
00020  * ***** END GPL LICENSE BLOCK *****
00021  */
00022 
00028 #ifndef REEB_H_
00029 #define REEB_H_
00030 
00031 #define WITH_BF_REEB
00032 
00033 #include "DNA_listBase.h"
00034 
00035 #include "BLI_graph.h"
00036 
00037 struct GHash;
00038 struct EdgeHash;
00039 struct ReebArc;
00040 struct ReebEdge;
00041 struct ReebNode;
00042 
00043 typedef struct ReebGraph {
00044     ListBase    arcs;
00045     ListBase    nodes;
00046     
00047     float length;
00048     
00049     FreeArc         free_arc;
00050     FreeNode        free_node;
00051     RadialSymmetry  radial_symmetry;
00052     AxialSymmetry   axial_symmetry;
00053     /*********************************/
00054     
00055     int resolution;
00056     int totnodes;
00057     struct EdgeHash *emap;
00058     int multi_level;
00059     struct ReebGraph *link_up; /* for multi resolution filtering, points to higher levels */
00060 } ReebGraph;
00061 
00062 typedef struct EmbedBucket {
00063     float val;
00064     int   nv;
00065     float p[3];
00066     float no[3]; /* if non-null, normal of the bucket */
00067 } EmbedBucket;
00068 
00069 typedef struct ReebNode {
00070     void *next, *prev;
00071     float p[3];
00072     int flag;
00073 
00074     int degree;
00075     struct ReebArc **arcs;
00076 
00077     int subgraph_index;
00078 
00079     int symmetry_level;
00080     int symmetry_flag;
00081     float symmetry_axis[3];
00082     /*********************************/
00083     
00084     float no[3];
00085 
00086     int index;
00087     float weight;
00088     int multi_level;
00089     struct ReebNode *link_down; /* for multi resolution filtering, points to lower levels, if present */
00090     struct ReebNode *link_up;
00091 } ReebNode;
00092 
00093 typedef struct ReebEdge {
00094     struct ReebEdge *next, *prev;
00095     struct ReebArc  *arc;
00096     struct ReebNode *v1, *v2;
00097     struct ReebEdge *nextEdge;
00098     int flag;
00099 } ReebEdge;
00100 
00101 typedef struct ReebArc {
00102     void *next, *prev;
00103     struct ReebNode *head, *tail;
00104     int flag;
00105 
00106     float length;
00107 
00108     int symmetry_level;
00109     int symmetry_group;
00110     int symmetry_flag;
00111     /*********************************/
00112 
00113     ListBase edges;
00114     int bcount;
00115     struct EmbedBucket *buckets;
00116 
00117     struct GHash *faces;    
00118     float angle;
00119     struct ReebArc *link_up; /* for multi resolution filtering, points to higher levels */
00120 } ReebArc;
00121 
00122 typedef struct ReebArcIterator {
00123     HeadFct     head;
00124     TailFct     tail;
00125     PeekFct     peek;
00126     NextFct     next;
00127     NextNFct    nextN;
00128     PreviousFct previous;
00129     StoppedFct  stopped;
00130     
00131     float *p, *no;
00132     float size;
00133     
00134     int length;
00135     int index;
00136     /*********************************/
00137     struct ReebArc  *arc;
00138     int start;
00139     int end;
00140     int stride;
00141 } ReebArcIterator;
00142 
00143 struct EditMesh;
00144 struct EdgeIndex;
00145 
00146 int weightToHarmonic(struct EditMesh *em, struct EdgeIndex *indexed_edges);
00147 int weightFromDistance(struct EditMesh *em, struct EdgeIndex *indexed_edges);
00148 int weightFromLoc(struct EditMesh *me, int axis);
00149 void weightToVCol(struct EditMesh *em, int index);
00150 void arcToVCol(struct ReebGraph *rg, struct EditMesh *em, int index);
00151 void angleToVCol(struct EditMesh *em, int index);
00152 void renormalizeWeight(struct EditMesh *em, float newmax);
00153 
00154 ReebGraph * generateReebGraph(struct EditMesh *me, int subdivisions);
00155 ReebGraph * newReebGraph(void);
00156 
00157 void initArcIterator(BArcIterator *iter, struct ReebArc *arc, struct ReebNode *head);
00158 void initArcIterator2(BArcIterator *iter, struct ReebArc *arc, int start, int end);
00159 void initArcIteratorStart(BArcIterator *iter, struct ReebArc *arc, struct ReebNode *head, int start);
00160 
00161 /* Filtering */
00162 void filterNullReebGraph(ReebGraph *rg);
00163 int filterSmartReebGraph(ReebGraph *rg, float threshold);
00164 int filterExternalReebGraph(ReebGraph *rg, float threshold);
00165 int filterInternalReebGraph(ReebGraph *rg, float threshold);
00166 
00167 /* Post-Build processing */
00168 void repositionNodes(ReebGraph *rg);
00169 void postprocessGraph(ReebGraph *rg, char mode);
00170 void removeNormalNodes(ReebGraph *rg);
00171 
00172 void sortNodes(ReebGraph *rg);
00173 void sortArcs(ReebGraph *rg);
00174 
00175 /*------------ Sanity check ------------*/
00176 void verifyBuckets(ReebGraph *rg);
00177 void verifyFaces(ReebGraph *rg);
00178 void verifyArcs(ReebGraph *rg);
00179 void verifyNodeDegree(ReebGraph *rg);
00180 
00181 /*********************** PUBLIC *********************************/
00182 
00183 #define REEB_MAX_MULTI_LEVEL    10
00184 
00185 struct bContext;
00186 
00187 ReebGraph *BIF_ReebGraphFromEditMesh(void);
00188 ReebGraph *BIF_ReebGraphMultiFromEditMesh(struct bContext *C);
00189 void BIF_flagMultiArcs(ReebGraph *rg, int flag);
00190 
00191 void BIF_GlobalReebGraphFromEditMesh(void);
00192 void BIF_GlobalReebFree(void);
00193 
00194 ReebNode *BIF_otherNodeFromIndex(ReebArc *arc, ReebNode *node);
00195 ReebNode *BIF_NodeFromIndex(ReebArc *arc, ReebNode *node);
00196 ReebNode *BIF_lowestLevelNode(ReebNode *node);
00197 
00198 ReebGraph *BIF_graphForMultiNode(ReebGraph *rg, ReebNode *node);
00199 
00200 void REEB_freeGraph(ReebGraph *rg);
00201 void REEB_freeArc(BArc *barc);
00202 void REEB_exportGraph(ReebGraph *rg, int count);
00203 void REEB_draw(void);
00204 
00205 
00206 #endif /*REEB_H_*/