#ifndef __TRIANGLEMESH__FOR_MT__ #define __TRIANGLEMESH__FOR_MT__ #include <vector> #include <i3d/image3d.h> #include "../src/params.h" /** * This is simple, minimalistically compatible (somewhat at the syntax level (*)) * class alternative to the main MotionTracking class ActiveMesh. * * (*) It uses standard container (std::vector) instead of those of MotionTracking (MArray). * Data from both containers, however, can be accessed in a syntactically the same fashion, * i.e., with pointers and []. Modifying lengths of the containers differ. * * (*) Also the Vector3F is different from the MotionTracking one, yet they are similar. * * It is meant for rapid trying/debugging of basic "mesh-processing" mesh-not-modifying algorithms. */ class ActiveMesh { public: std::vector<Vector3FC> Pos; //list of mesh vertices std::vector<long unsigned int> ID; //list of triangles organized in tripplets of indices into the Pos array of vertices; //the array length should be 3x the number of triangles in the mesh std::vector<Vector3F> norm; //list of vectors that are normal/orthogonal to the planes given by the individual triangles /** * Determine coeffs that represent the local surface around vertex \e vertexID. * * Any point [x,y,z] on the curve satisfies the equation: * Scalar product of \e coeffs and [1,x,y,z,xy,xz,yz,x^2,y^2,z^2] = 0. * This also explains the order (and meaning) of the \e coeffs array. * Order was adopted from [1], eq (2), page 3. * * The algorithm has been implemented according to * the "instructions" [2], Appendix A, page 131. * * [1]: Dong-Ming Yan, Wenping Wang, Yang Liu, Zhouwang Yang. * Variational mesh segmentation via quadric surface fitting. * Elsevier: Computer-Aided Design 44 (2012), pp. 1072-1082. * * [2]: Hui Ma, Geometric Fitting of Quadratic Curves and Surfaces, * Dissertation Thesis, Univ. Alabama, 2011. */ int CalcQuadricSurface_Taubin(const int vertexID, float (&coeffs)[10]); /** * Calculate the 3rd coordinate (e.g., z) to complete a 3D point * [x,y,z] given the other two coordinates (e.g., x and y). * The point should lay on the quadric surface given with * the coefficients \e coeffs. * * Returns false if such point could not be determined. * * Note that due to symmetries in the equations, one can use * the very same function to obtain x given y,z, etc. * * Also note that two points are actually generated, one need * to examine their distance to the point around which the surface * has been calculated, and take the closer one. */ bool GetPointOnQuadricSurface(const float x,const float y, float &z1, float &z2, const float (&coeffs)[10]); ///Adjusts the input \e point to arrive at the surface given by its \e coeffs, ///the value of \e point is, therefore, changed. float GetClosestPointOnQuadricSurface(Vector3F& point, const float (&coeffs)[10]); ///returns index of the closest from \e points to the \e point int ChooseClosestPoint(const std::vector<Vector3F>& points, const Vector3F& point); ///input is filename ///returns 0 on success, otherwise non-zero int ImportSTL(const char* filename); int ImportVTK(const char* filename); void RenderMask(i3d::Image3d<i3d::GRAY16>& mask); void RenderMaskB(i3d::Image3d<i3d::GRAY16>& mask); void CenterMesh(const Vector3F& newCentre); void ScaleMesh(const Vector3F& scale); //the following functions are all defined in graphics.cpp void displayMesh(void); void displayVertexAndNeigs(void); void displayQuadricSurface(void); }; #endif