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