//! file="amma/Surf3d/HoppeOpt/HoppeSlime.hh" //! lib=HoppeOpt //! userlevel=Default //! docentry="default.Andrew Stoddart" //! rcsid="$Id: HoppeSlime.hh,v 1.4 2000/07/07 12:58:33 ees1cg Exp $" //! author="Andrew Stoddart" //! date="25/02/98" // ------------------------------------------------------------------------- // ********** MeshOptC ******************************************* // ------------------------------------------------------------------------- #ifndef MeshOptTri_HH #define MeshOptTri_HH #include "amma/Slime.hh" #include "amma/KwList.hh" #include // ------------------------------------------------------------------------- // ------------------------------------------------------------------------- struct PointStuffC { double d; // the distance to the nearest point Vector3dC v; // the data point Vector3dC uv; t_uM uM; int idx; }; // ------------------------------------------------------------------------- typedef DListC HSListC; typedef DLIterC HSLIterC; // ------------------------------------------------------------------------- class PLBackupC { public: ItVertC iv; HSListC pList; PLBackupC(); // Null Constructor PLBackupC(ItVertC iv0, const HSListC & pl); // Construct from iv and grab a copy of the PList PLBackupC(const PLBackupC & s); // Copy constructor PLBackupC & operator=(const PLBackupC & s); // Assignment ~PLBackupC(); // Destructor }; // ------------------------------------------------------------------------- // ********** HopSlimeC ************************************************ // ------------------------------------------------------------------------- // // Note about the Nearest Neighbour strategy. // // (u,v) will not be exact, but d will be an exact distance |d-r(u,v)| // // // // REMEMBER : Slime patches correspond to VERTICES // FACES are collapsed // // // ------------------------------------------------------------------------- class HopSlimeC { public: SlimeC sl; VTRingC vt; // Note that Slime also has a vt member - these should be handles to the // same thing private: int blocksize; double cost_spring; //const double cost_data = 1.0; double cost_rep; double cost_vert; ostream *log; public: // Constructors, destructor, assignment // ------------------------------------- HopSlimeC(); // Null Constructor HopSlimeC(SlimeC & sl); // Constructor, takes a handle to vt private: HopSlimeC(const HopSlimeC & s); // Copy constructor HopSlimeC & operator=(const HopSlimeC & s); // Assignment public: ~HopSlimeC(); // Destructor public: // Called by user // -------------- // // // void SetConst(double ks, double kr, double kv); // Set the constants to new values, must be called!! void UseStuffToRecomputeDist(ItVertC iv, PointStuffC & p); // Using the local weighting factors in stuff and the current // control point positions recompute the distance, // dont repeat the NN search void FindDistLoadStuff(ItVertC iv, PointStuffC & p); // given patch iv and p.v find closest point returning d, uv, uM // if iv is not a valid patch DO NOTHING double DistToPatch(ItVertC iv, const Vector3dC & data); // given patch iv and p.v find closest point returning data // if iv is not a valid slime patch return a BIG number void MakeMap(VectorSetC & points, char * mapfile, int ngrid); // write a file containing the nearest vertex foreach point void OldMakeMap(VectorSetC & points, char * mapfile, double th=0); // write a file containing the nearest vertex foreach point void LoadMap(VectorSetC & points, char * mapfile); // read file containing the nearest vertex foreach point // call DistToPatch(ItVertC iv, PointStuffC & p); to set uv & uM //void SaveMap(VectorSetC & points, char * mapfile); void ReprojectOnNeighbours(ItVertC iv); // reproject all the points attached to patch iv onto iv or one of // its neighnours that shares an edge // all data inside PStuff is updated for each data point considered void ReprojectWithinOnePatch(ItVertC iv); // reproject all the points attached to patch iv within patch iv // all of PStuff is updated for all points HSListC & PListOf(const ItVertC & iv); // return a reference to the list on patch iv void ShowStats(); // compute and display some statistics double ComputeEnergy(int t) ; // compute the overall energy, print if (t) double ComputeLocalSpringEnergy(DListC &nhood, int t); // compute the spring energy in neighbourhood "nhood", print if (t) double ComputeLocalDataEnergy(DListC &nhood, int t); // compute the data energy in neighbourhood "nhood", print if (t) double Compute_Spring_Energy(ItVertC iv); // compute the spring energy, /2 to avoid double counting double Compute_Data_Energy(ItVertC iv); // compute the data energy using values in PointStuffC double RefinePosn(ItVertC iv); // considering uv fixed, for one vertex, this solves a quadratic to // minimize the sum of data and spring energies void CheckRefine(HSListC & plist, SArray1dC & control, Vector3dC & vmid); // a check used to debug RefinePosn(ItVertC iv), it computes the // data and spring energies void OptimizeVectors(int nrefine, int niterate); // void OptimizeMesh(int nrefine); // BooleanT UnmarkedFaces(); // returns TRUE if there are unmarked faces in "vt", FALSE otherwise BooleanT IsFaceMarked(VTFaceC &f); // returns TRUE if "f" is marked, FALSE otherwise ItTriC FirstUnmarkedFace(); // returns iterator of first unmarked patch in "vt", if none left then // return ... void MarkFaceandMovetoEnd(ItTriC &it); // marks face "it" and moves it to the end of "vt" void RemoveDuplicates(DListC &list1); void RemoveDuplicates(DListC &list1, DListC &list2); // //ItTriC UncollapseFaceandMovetoEnd(TEdgeC te1, TEdgeC te2, ItTriC &itnew, // ItVertC iv1, ItVertC iv2); // Undoes a face collapse by calling vt.ExpandFace with "te1", "te2", // "v1" and "v2". BooleanT CollapseFace(ItTriC face, ItVertC iv1, ItVertC iv2, ItVertC &ivnew, TEdgeC &te1, TEdgeC &te2); // Performs a aface collapse, saving information necessary to undo the // collapse. BooleanT FaceCollapseAllowed(ItTriC it, ItVertC &iv1, ItVertC &iv2); // returns TRUE if and only if "it" can be collapsed on it's shortest // diagonal, sets iv1 and iv2 to the vertices that will disappear BooleanT ExpandFace(TEdgeC te1, TEdgeC te2, ItTriC &itnew, ItVertC &iv1, ItVertC &iv2); // expands a face along the TEdges "te1" and "te2". No checking is // performed as it is assumed that "te1" and "te2" were returned by // FaceExpandAllowed(). Returns the new face "itnew" and the two new // verts "iv1" and "iv2" BooleanT FaceExpandAllowed(ItTriC it, TEdgeC &te1, TEdgeC &te2, ItVertC &ivold); // determines if face expand can be performed on a vertex of face "it". // if so, the TEdges "te1" and "te2" neccessary for FaceExpand() are // returned. The vertex that will be removed, "ivold" is also returned. void GetNeighbourhood(ItVertC iv, ItTriC face, DListC &nhood); // makes a copy of the verts forming a neighbouhood of "iv" that don't // belong to "face". void GetVertsAroundNeighbourhood(DListC nhood, DListC& list); // creates a list of all the vertices around the vertices in "nhood", // returning the list in "list". void RestoreNeighbourhood(DListC &nhood); // restores neighbourhood of vertices in "nhood". void OptimizeOneVertex(ItVertC iv, int refine); void SetLogFile(ostream *log); // temporary hack. if this is not null, expand and collapse operations // will be logged to this file. }; #endif //----------------------------------------------------------------------------------------- // End of include file HopSlime.hh //-----------------------------------------------------------------------------------------