/Users/craigcornelius/Projects/SPRING Mac Release 0.2/node.h

Go to the documentation of this file.
00001 // $Id: node.h,v 1.69 2006/05/24 16:52:41 sean Exp $
00002 // $Copyright: (c)2001 National Biocomputation Center, Stanford University $
00003 
00004 #ifndef Node_H
00005 #define Node_H
00006 
00007 #include "util.h"
00008 #include "point3d.h"
00009 #include "reallocablearray.h"
00010 //#include "boundingsphere.h"
00011 
00012 // Note: no more MAXDEGREE- now edges and faces arrays are ReallocableArrays
00013 
00014 class Edge;
00015 class Face;
00016 class Tetra;
00017 class NodeArray;
00018 class BoundingSphereLeaf;
00019 
00020 class Node
00021 {
00022 public:                        
00023     // publicly used vars
00024     Point3D p;           // position
00025     Point3D init_pos;    // initial position
00026     Point3D v;           // velocity
00027     Point3D p_old;       // these are used in RK2 and RK4, for now
00028     Point3D v_old;
00029     Point3D p_mid;
00030     Point3D v_mid;
00031     Point3D p_mid2;
00032     Point3D v_mid2;
00033     Point3D delta;                     // for hacky use in findFaceCollisions
00034     
00035     // indicates whether a node has fixed position or velocity or neither
00036     enum Fixtype {NOT, POS, VEL};
00037     
00038     // indicates what type of texture coord model we have
00039     enum texture_coord_type {linear, cylindrical, spherical};    
00040     
00041     BoundingSphereLeaf* boundingsphere;
00042     
00043 private:
00044     Point3D n;                         // normals
00045     Point3D f;                         // total force applied to this node
00046     Point3D f_ext;                     // external force applied to this node
00047     Point3D t;                         // texture coordinates
00048 
00049     Point3D edge_sum;                  // sum of the edge vectors surrounding this node
00050         Point3D init_edge_sum;             // initial sum of the ed...
00051   
00052         Node* tie_node;                                  // other node we are tied to
00053    
00054         int skipnum;                       // steps of force recalculation to skip
00055     double mass;
00056     double velocityDampConstant;       // for viscous (ABSolute) damping
00057    
00058         Fixtype fixed;
00059     
00060         ReallocableArray<Edge*> edges;    // reallocable array of edge pointers
00061     ReallocableArray<Face*> faces;    // reallocable array of face pointers
00062         ReallocableArray<Tetra*> tetras;        // reallocable array of tetra pointers
00063 
00064         int part_id;                                            // for vertex coloring/subobjects
00065     int level;
00066     long cached_index;    // for fast index lookup:see NodeArray::CacheIndices
00067     
00068     NodeArray* nodearray_p;
00069     
00070     Node* collision;    // FOR TESTING- who we're colliding with
00071     
00072 public:
00073     Node();
00074     ~Node();
00075     static const char* rcsid;
00076     static int debug;
00077     static double deltatime;   // make timestep a static class member
00078     
00079     // initialization
00080     int init(NodeArray* nodearray_p, char* initString);
00081     int init(NodeArray* nodearray_p, double x_in, double y_in, double z_in, 
00082         double nx_in=0.0, double ny_in=0.0, double nz_in=1.0,    // normal
00083         double vx_in=0.0, double vy_in=0.0, double vz_in=0.0, // velocity
00084         double u_in=0.0, double v_in=0.0,            // texture coords
00085         Fixtype fixed_in=NOT, double mass_in=1.0);    // misc
00086     
00087     BoundingSphereLeaf* getBoundingSphere();
00088     void setBoundingSphere(BoundingSphereLeaf* sphere);
00089     Point3D getCenter();
00090     double getRadius();
00091     
00092     // topology/link routines
00093     int getIndex(void);
00094     void setCachedIndex(long index);
00095     long getCachedIndex();
00096 
00097         int isConnectedTo(Node* n);
00098 
00099     int IsOnTheBorder(void);
00100     int is_on_the_border();
00101 
00102     void addEdgeLink(Edge *e);
00103     void deleteEdgeLink(Edge *e);
00104     Edge* getEdgeLink(int index);
00105     Edge* findEdgeLink(Node* adjacentNode);
00106     int hasEdgeLink(Edge* e);
00107     int numEdgeLinks();
00108     Edge *is_adjacent_to(Node* n);
00109 
00110     void addFaceLink(Face *f);
00111     void deleteFaceLink(Face* f);
00112     Face* getFaceLink(int index);
00113     int numFaceLinks();
00114     int hasFaceLink(Face* f);
00115         Face* isAFaceWith(Node* n0, Node* n1);
00116 
00117         void addTetraLink(Tetra *t);
00118         void deleteTetraLink(Tetra* t);
00119         Tetra* getTetraLink(int index);
00120         int numTetraLinks();
00121         int hasTetraLink(Tetra* t);
00122 
00123 
00124     NodeArray* getNodeArray(void) {return nodearray_p;}
00125 
00126     Point3D getNormal();
00127     Point3D getCurvature();
00128 
00129     void setNewStableInitPos(Point3D newpos);
00130 
00131     Node* FindClosestAdjacentNode(Point3D p);
00132     Node* FindClosestAdjacentNodeToFace(Face* f_p);
00133 
00134     int SanityCheck(NodeArray* na_p);    // returns 1 if ok
00135     
00136     // simulation stuff
00137     void setF(Point3D force) {f = force;}
00138     Point3D getF(void) {return f;}
00139     void setFext(Point3D force) {f_ext = force;}
00140     Point3D getFext(void) {return f_ext;}
00141     void addForce(Point3D force) {f = f + force;}
00142 
00143     double getEnergy(void);
00144     double getMass();
00145     void setMass(double mass);
00146 
00147     double getVelocityDampConstant();
00148     void setVelocityDampConstant(double value);
00149 
00150     void setFixedType(Fixtype fixed);
00151     Fixtype getFixedType(void) {return fixed;}
00152 
00153     void findPosition(void);
00154     void findFSAEverything(double elapsed_time);
00155     void findVelocity(void);
00156     void findMidpointRK(void);
00157     void findMidpoint2RK4(void);
00158     void findGuessRK4(void);
00159     void findFinalRK2(void);
00160     void findFinalRK4(void);
00161     //  void findFSAForce(void);
00162 
00163         
00164         void findForceFromEdges(int damped);
00165         void findForceDampFull();
00166         void findForceDampRel(void);
00167         void findForceDampAbs(void);
00168     
00169         // This is an older, less efficient method, but it works.
00170     void findForce(int damped);
00171 
00172         // For quasistatic computations.  No damping used.
00173     Point3D findSpringForce(void);
00174         void findQuasiForceFromEdges(void);
00175 
00176 
00177     void forceDisplace(double scale);
00178 
00179     void moveTestLine(Node *n1, Node *n2);
00180 
00181     // decimation handling
00182     void Adjacents(Node *adjacents[]);
00183     void AdjacentsSort(Node *set[], int setSize, Point3D normal, int *initTest, 
00184         int headIndex);
00185 
00186     void SetOutput(Node *set[], Node *output[], int testConcavity, int setSize);
00187  
00188         void ClipEar(int i, int n, Node* poly[], int labels[]);
00189     void PointAssign(Node* n);
00190     bool Diagonal(int i, int j, int n, Node* poly[], Point3D normal);
00191     bool InCone(int i, int j, int n, Node* poly[], Point3D normal);
00192     bool Diagonalie(int i, int j, int n, Node* poly[], Point3D normal);
00193     bool Intersect(Node* b, Node* c, Node* d, Point3D normal);
00194     bool Between(Node* b, Node* c, Point3D normal);
00195     bool IntersectProp(Node* b, Node* c, Node* d, Point3D normal);
00196     bool Left(Node* a, Node* b, Point3D normal);
00197     bool LeftOn(Node* a, Node* b, Point3D normal);
00198     bool Colinear(Node* a, Node* b);
00199     double SignedArea(Node* a, Node* b, Point3D normal);
00200     
00201     // collision handling
00202     int processCollisions(NodeArray* na_p);
00203     void resetCollisions();
00204     void setCollisionNode(Node* n);
00205     Node* getCollisionNode();
00206     double DistanceToAnyOfMyFaces(Point3D pt);
00207     
00208     // graphics
00209     void computeInitialEdgeSum();
00210     void interpolateNormal(void);
00211         void interpolateTetraNormal();
00212     void draw(int do_color, int do_objectwide_color, int do_texture);
00213     void drawlabel(float offset);
00214     void drawover(double scale);
00215     void drawnormal();
00216     void drawinitial();
00217     void drawtienode();
00218     void computeTextureCoords(texture_coord_type textype);
00219     Point3D getTextureCoords();
00220     void setTextureCoords(double u, double v);
00221                 void setTextureCoords(Point3D tc);
00222     
00223     // for vertex coloring/subobjects
00224     int getPartId();
00225     void setPartId(int part_id_in);  
00226     void SpreadColor(int new_color);
00227     Node* FindColoredAdjacentNode(int color);
00228     Node* FindDifferentColoredAdjacentNode(int color);
00229     void ColorMeshForSplitAtNode(Node* other_node);
00230     Node* SplitColoredMeshAtNode(Node* other_node);
00231     
00232     // for helping ordered numerical methods?
00233     int getLevel();
00234     void setLevel(int level_in);
00235     
00236     // misc
00237     void setTieNode(Node* other_node);
00238     Node* getTieNode();
00239                 //mass distribution
00240                 double VoronoiArea(); 
00241                 double TriPointArea(Point3D one, Point3D two, Point3D three); 
00242                 void OrderFaces(Face **orderme, int cur_index);
00243                 Point3D ClosestIntersect(Point3D p1, Point3D p2, Point3D p3, Point3D p4);
00244     
00245     // output
00246     void Print();
00247     void SaveAsMesh(ostream& os);
00248     friend ostream& operator<<(ostream& os, const Node& n);
00249 };
00250 
00251 inline BoundingSphereLeaf* Node::getBoundingSphere()
00252 { return(boundingsphere); }
00253 
00254 inline void Node::setBoundingSphere(BoundingSphereLeaf* sphere)
00255 { boundingsphere = sphere; }
00256 
00257 inline Point3D Node::getCenter()
00258 { return (p); }
00259 
00260 inline double Node::getRadius()
00261 { return (0.0); }
00262 
00263 inline Edge* Node::getEdgeLink(int index)
00264 {
00265     if ((index < 0) || (index >= edges.NumElements()))
00266         return(NULL);
00267     else return(edges[index]);
00268 }
00269 
00270 inline int Node::hasEdgeLink(Edge* e)
00271 {
00272     for (int i=0; i<edges.NumElements(); i++)
00273         if (edges[i] == e) return(1);
00274         return(0);
00275 }
00276 
00277 inline int Node::numEdgeLinks()
00278 { return (edges.NumElements()); }
00279 
00280 inline Face* Node::getFaceLink(int index)
00281 {
00282     if ((index < 0) || (index >= faces.NumElements()))
00283         return(NULL);
00284     else return(faces[index]);
00285 }
00286 
00287 inline int Node::numFaceLinks()
00288 { return(faces.NumElements()); }
00289 
00290 inline int Node::hasFaceLink(Face* f)
00291 {
00292     for (int i=0; i<faces.NumElements(); i++)
00293         if (faces[i] == f) return(1);
00294         return(0);
00295 }
00296 
00297 inline int Node::hasTetraLink(Tetra* t)
00298 {
00299   for (int i=0; i<tetras.NumElements(); i++)
00300         if (tetras[i] == t) return(1);
00301   return(0);
00302 }
00303 
00304 inline Tetra* Node::getTetraLink(int index)
00305 {
00306   if ((index < 0) || (index >= tetras.NumElements()))
00307     return(NULL);
00308   else return(tetras[index]);
00309 }
00310 
00311 inline double Node::getMass()
00312 { return(mass); }
00313 
00314 inline void Node::setMass(double mass_in)
00315 { mass = mass_in; }
00316 
00317 inline double Node::getVelocityDampConstant()
00318 { return(velocityDampConstant); }
00319 
00320 inline void Node::setVelocityDampConstant(double value)
00321 { velocityDampConstant = value; }
00322 
00323 inline Point3D Node::getNormal()
00324 { return(n); }
00325 
00326 inline void Node::resetCollisions()
00327 { collision = NULL; }
00328 
00329 inline Node* Node::getCollisionNode()
00330 { return(collision); }
00331 
00332 inline void Node::setCollisionNode(Node* n)
00333 { collision = n; }
00334 
00335 inline void Node::setFixedType(Fixtype fixed_in)
00336 { fixed = fixed_in; }
00337 
00338 inline int Node::getPartId()
00339 { return(part_id); }
00340 
00341 inline void Node::setPartId(int part_id_in)
00342 { part_id = part_id_in; }
00343 
00344 inline int Node::getLevel()
00345 { return(level); }
00346 
00347 inline void Node::setLevel(int level_in)
00348 { level = level_in; }
00349 
00350 inline void Node::setCachedIndex(long index)
00351 { cached_index = index; }
00352 
00353 inline long Node::getCachedIndex()
00354 { return(cached_index); }
00355 
00356 inline Point3D Node::getTextureCoords()
00357 { return(t); }
00358 
00359 inline void Node::setTextureCoords(Point3D tc)
00360 { t = tc; }
00361 
00362 inline void Node::setTextureCoords(double u, double v)
00363 { t.x = u; t.y = v; t.z = 1.0; }
00364 
00365 inline void Node::setTieNode(Node* other_node)
00366 { tie_node = other_node; }
00367 
00368 inline Node* Node::getTieNode()
00369 { return(tie_node); }
00370 
00371 #endif

Generated on Thu Aug 30 11:03:14 2007 for SPRING Mac by  doxygen 1.5.3