1 #ifndef CONTROLPOINT_H_
2 #define CONTROLPOINT_H_
3 
4 /****************************************************************************
5 * Rgb Triangulations Plugin                                                 *
6 *                                                                           *
7 * Author: Daniele Panozzo (daniele.panozzo@gmail.com)                       *
8 * Copyright(C) 2007                                                         *
9 * DISI - Department of Computer Science                                     *
10 * University of Genova                                                      *
11 *                                                                           *
12 * All rights reserved.                                                      *
13 *                                                                           *
14 * This program is free software; you can redistribute it and/or modify      *
15 * it under the terms of the GNU General Public License as published by      *
16 * the Free Software Foundation; either version 2 of the License, or         *
17 * (at your option) any later version.                                       *
18 *                                                                           *
19 * This program is distributed in the hope that it will be useful,           *
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
22 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)          *
23 * for more details.                                                         *
24 ****************************************************************************/
25 
26 
27 #include <vcg/space/point3.h>
28 #include "rgbInfo.h"
29 #include <common/meshmodel.h>
30 #include "rgbPrimitives.h"
31 #include "topologicalOp.h"
32 
33 namespace rgbt
34 {
35 //! Contain all the function needed to compute the coordinate of the vertexes.
36 /** Is based on a loop subdivision adapted for the use on an rgb triangulation */
37 class ControlPoint
38 {
39     /// The tetrahedral mesh type
40     typedef CMeshO TriMeshType;
41     /// The face type
42     typedef TriMeshType::FaceType FaceType;
43     /// The vertex type
44     typedef FaceType::VertexType VertexType;
45     /// The vertex type pointer
46     typedef FaceType::VertexType* VertexPointer;
47     /// The vertex iterator type
48     typedef TriMeshType::VertexIterator VertexIterator;
49     /// The tetra iterator type
50     typedef TriMeshType::FaceIterator FaceIterator;
51     /// The coordinate type
52     typedef FaceType::VertexType::CoordType CoordType;
53     /// The scalar type
54     typedef TriMeshType::VertexType::ScalarType ScalarType;
55     ///the container of tetrahedron type
56     typedef TriMeshType::FaceContainer FaceContainer;
57     ///the container of vertex type
58     typedef TriMeshType::VertContainer VertContainer;
59     ///half edge type
60     typedef TriMeshType::FaceType::EdgeType EdgeType;
61     /// vector of pos
62     typedef std::vector<EdgeType> EdgeVec;
63     /// Face Pointer
64     typedef TriMeshType::FacePointer FacePointer;
65     /// Edge defined by Face and Index
66     typedef EdgeFI<FacePointer> EdgeFIType;
67     /// Topological Operation Class
68     typedef TopologicalOp<CMeshO,RgbInfo::VERTEXC,RgbInfo::FACEC > TopologicalOpC;
69     /// A Point
70     typedef vcg::Point3f Point;
71 	/// RGB Triangle
72     typedef RgbTriangle<CMeshO> RgbTriangleC;
73     /// RGB Vertex
74     typedef RgbVertex<CMeshO> RgbVertexC;
75 
76 public:
77 
78 	//ControlPoint(CMeshO& m, RgbInfo& i, TopologicalOpC& to);
79 	//virtual ~ControlPoint();
80 	/// Compute the Pinf of the base vertexes
81 	static void init(TriMeshType& m, RgbInfo& info);
82 
83 	/// find the 4 vertexes of the stencil
84     /**
85      * firstVertex return the eventual point that can contribute to the Pinf of the newvertex
86      */
87 	static void findInitialStencil(RgbTriangleC& t, int EdgeIndex,int level, TopologicalOpC& to, vector<RgbVertexC>* indexes = 0,vector<RgbVertexC>* firstVertexes = 0);
88 	/// Compute and assign PInf (it perform split on the green edge if necessary)
89 	static void assignPinf(RgbVertexC& v,bool initial = false);
90 	/// Recompute Pkl with k the minimal level of incident edges
91 	static Point computePkl(RgbVertexC& v,int kl);
92 	/// Compute alpha(k)
93 	static double alpha(int n);
94 	/// Compute alpha(k,n)
95 	static double gamma(int n,int k);
96 	/// compute Pl starting from the stencil
97 	/** vector must have size 4, first two vertexes are the two that incides
98 	 * with the edge that has to be splitted
99 	 */
100 	static Point computePl(int l, vector<RgbVertexC>& stencil);
101 	static Point computePlBoundary(int l,vector<RgbVertexC>& stencil);
102 
103 	/// If necessary update the current vertex position
104 	/**
105 	 * It require Pinf for the current vertex
106 	 */
107 	static void updateP(RgbVertexC& v);
108 	/// Add the contibute of p at the vIndex vertexes
109 	static void addContribute(RgbVertexC& v,Point& p, bool update = true);
110 	/// Remove the contibute of p at the vIndex vertexes
111 	static void removeContribute(RgbVertexC& v,Point& p);
112 
113     //! Perform an edge split with the correct computation of the new vertex coordinates
114 	/* Return true if on the current edge was performed only a topological split
115 	 * return false if a complete split (with update on rgb Info) was performed. the complete split is performed
116 	 * during the calculation og the stencil
117 	 */
118     static bool doSplit(RgbTriangleC& fp, int EdgeIndex, int level, TopologicalOpC& to , vector<FacePointer> *vfp = 0, RgbVertexC* vNewInserted = 0, vector<RgbVertexC>* vcont = 0, vector<RgbVertexC>* vupd = 0);
119 
120     //! Perform an edge collapse
121     static void doCollapse(RgbTriangleC& fp, int EdgeIndex, TopologicalOpC& to, Point3<ScalarType> *p = 0, vector<FacePointer> *vfp = 0);
122     //! Return the minimal level of incident edge
123     static int minimalEdgeLevel(RgbVertexC& v);
124     /// Search in VV relation all vertexes that contribute on Pinf of v
125     static void searchContribute(RgbVertexC& v, bool update = true);
126     /// Search in VV relation the two boundary vertexes that contribute on Pinf of v when v is on the Boundary
127     static void searchContributeBoundary(RgbVertexC& v,bool update);
128     /// Search in VV relation all vertexes that need contribution from v (is called once per vertex after Pinf become available)
129     static void addPinfContributeToVV(RgbVertexC& v);
130 
131     //static void removeContributeToVV(RgbVertexC& v);
132     /// If possible add the contribute of orig to dest. If Execute is equal to false do not perform the operation, only return true if possible false otherwise.
133     static bool addContributeIfPossible(RgbVertexC& dest, RgbVertexC& orig, bool execute = true);
134     /// Add the vertex orig to the taken list of dest and the vertex dest to the given list of orig
135     static void addToLists(RgbVertexC& dest, RgbVertexC& orig);
136     /// Remove the vertex orig to the taken list of dest and the vertex dest to the given list of orig
137     static void removeFromLists(RgbVertexC& dest, RgbVertexC& orig);
138     /// Clear the taken list and clear the given list(removing all the link to other vertexes)
139     /**
140      * l will contain a copy of the given list of v
141      */
142     static void listUpdateVertexRemoval(RgbVertexC& v, list<RgbVertexC>& l);
143     /// Detach all the link when a vertex is removed (also clear the given and taken lists)
144     static void vertexRemovalUpdate(RgbVertexC& v);
145     /// Clear the taken list removing all the links
146     static void cleanTakenList(RgbVertexC& v);
147 
148     //! Count the number of incident edges (not use any relation if vertex level > 0)
149     static unsigned int vertexRank(RgbVertexC& v);
150 };
151 
152 }
153 
154 #endif /*CONTROLPOINT_H_*/
155