// onvexSkirtTriMeshSdfAlgorithm.h: interface for the ConvexSkirtTriMeshSdfAlgorithm class. // ////////////////////////////////////////////////////////////////////// #if !defined(AFX_ONVEXSKIRTTRIMESHSDFALGORITHM_H__5BCEF0F9_F201_4282_A174_87007CC30196__INCLUDED_) #define AFX_ONVEXSKIRTTRIMESHSDFALGORITHM_H__5BCEF0F9_F201_4282_A174_87007CC30196__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #include "TriMeshSDFAlgorithm.h" #include "ADFCreator_debug_flags.h" #include "Utils.h" #include #include using namespace std; #include "datalib.h" // for Tuples namespace SDF { //----------------------- // A bunch of helper data structures //----------------------- typedef vector TriangleList; typedef vector TriangleListList; typedef vector VertexList; typedef Pair PointPair; typedef Pair TrianglePair; typedef Pair IndexPair; typedef Pair SortedUmbrella; class ClosestTriSet { friend ostream& operator<< (ostream &os, const ClosestTriSet &set); public: ClosestTriSet(const double &abs_dist, const PointOnTriangle &pot) : abs_dist(abs_dist), p(pot) { } ~ClosestTriSet() { // Clear all triangles in the list - we own them // This is quite important to avoid memory leak.. TriangleList::iterator itr; for(itr = this->tris.begin(); itr != this->tris.end(); ++itr) { MeshTriangle *ptr = *itr; if(ptr != NULL) { delete ptr; } } this->tris.clear(); } double abs_dist; PointOnTriangle p; TriangleList tris; }; //----------------------- // Comparator used for comparing to tri sets //----------------------- class TriSetCloser : std::binary_function { public: bool operator()(const ClosestTriSet* x, const ClosestTriSet* y) const { return (x->abs_dist) < (y->abs_dist); } }; //--------------------------------- // The main algorithm class //--------------------------------- class ConvexUmbrellaTriMeshSdfAlgorithm : public TriMeshSdfAlgorithm { protected: //-------------------------------- // Algorithm state vars //-------------------------------- #define REASONABLE_DISTANCE_CUT_OFF 10.0f // Our best candidate sets so far list tri_sets; // The point we want to calculate SDF for Point test_point; enum FoldType {FLAT, CONCAVE, CONVEX}; public: static void Test_sort_umbrella(); static void Test_find_vert(); static void Test_all(); ConvexUmbrellaTriMeshSdfAlgorithm() { this->start_new_computation(Point(0,0,0)); } ConvexUmbrellaTriMeshSdfAlgorithm(const Point &test_point) { this->start_new_computation(test_point); } void start_new_computation(const Point &test_point); virtual ~ConvexUmbrellaTriMeshSdfAlgorithm(); //-------------------------------- // Overrides //-------------------------------- void feed_triangle(const MeshTriangle &tri); virtual SdfValue compute_sdf_result(); protected: PointClass classify_pt_by_two_best_triangles(const ClosestTriSet &set); PointClass classify_pt_by_single_best_triangle(const MeshTriangle &tri, const Point &pc ); // Variations on this algorithm may want to modify this case. virtual PointClass classify_pt_by_umbrella_tris( const TriangleList &tris, const Point &x, const Point &p); PointClass classify_pt_by_fold( const MeshTriangle &a, const MeshTriangle &b ); FoldType calc_fold_type(const MeshTriangle &a, const MeshTriangle &b); Vector calc_angle_weighted_pseudo_normal(const ClosestTriSet &set); Vector calc_gradient(const ClosestTriSet &set); Vector pseudo_normal_to_gradient(const Vector &pnorm); private: //-------------------------------- // Statics //-------------------------------- // static TrianglePair Find_radial_min_max_of_triangles(const Vector &normal, const TriangleList &tris); static VertexList* Project_umbrella_rays( const Point &x, const VertexList &verts, const Plane &plane); static SortedUmbrella *Sort_by_umbrella_verts( const TriangleList &T, const Point &x); }; } #endif // !defined(AFX_ONVEXSKIRTTRIMESHSDFALGORITHM_H__5BCEF0F9_F201_4282_A174_87007CC30196__INCLUDED_)