Skip to content
Snippets Groups Projects
TriangleMesh.h 2.25 KiB
Newer Older
#ifndef __TRIANGLEMESH__FOR_MT__
#define __TRIANGLEMESH__FOR_MT__

#include <vector>
#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.
	 * 
	 * 
	 * [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.
	 */
	int CalcQuadricSurface_Taubin(const int vertexID,
	                              float (&coeffs)[10]);



	///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);

	void displayMesh(void); //defined in graphics.cpp
};

#endif