1 #ifndef INTERACTIVEEDIT_H_
2 #define INTERACTIVEEDIT_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  * The code of the class InteractiveEdit is based on the plugin editpaint,   *
28  * developed by Gfrei Andreas.                                               *
29  ****************************************************************************/
30 
31 
32 #include <math.h>
33 #include <stdlib.h>
34 #include <meshlab/glarea.h>
35 #include <stdio.h>
36 #include <wrap/gl/pick.h>
37 #include <limits>
38 
39 #include<vcg/complex/algorithms/update/topology.h>
40 #include<vcg/complex/algorithms/update/bounding.h>
41 
42 #include "rgbPrimitives.h"
43 #include "topologicalOp.h"
44 
45 namespace rgbt
46 {
47 
48 /** the different painting types */
49 typedef enum {PEN, FILL, PICK, NONE, GRADIENT, SMOOTH, SELECT, POLY_SMOOTH} PaintThing;
50 
51 /** contains some info about the current paint util */
52 struct Penn {
53 	float radius;
54 	int paintutensil;
55 	int painttype;
56 	bool backface;
57 	bool invisible;
58 };
59 
60 struct Vert_Data {
61 	CVertexO * v;
62 	float distance;
63 };
64 
65 struct Vert_Data_2 {
66 	float distance;
67 	Color4b color;
68 };
69 
70 struct Vert_Data_3{
71 	float pos[3];
72 	Color4b color;
73 };
74 
75 class InteractiveEdit
76 {
77 public:
78 	InteractiveEdit();
79 	virtual ~InteractiveEdit();
80 
81 	QPoint start; // mousepos at press
82 	QPoint prev;
83 	QPoint cur; // current mousepos
84 
85 	bool isDragging;
86 	int pressed; // to check in decorate if it is the first call after a mouse down or mouse up
87 	bool first; // to check in decorate if it is the first call after a mouse down
88 	double mvmatrix[16]; //modelview
89 	double projmatrix[16]; //projection
90 	GLint viewport[4]; //viewport
91 	GLfloat *pixels; // the z-buffer
92 	int inverse_y; // gla->curSiz.height()-cur.y() TODO probably removable
93 	vector<CMeshO::FacePointer> tempSel; //to use when needed
94 	list<int> curSel; //the faces i am painting on
95 	QHash<CVertexO *,Vert_Data_2> visited_vertexes; //the vertexes i am painting on
96 	Penn pen; //contains informations about the painting mode, color, type ...
97 	Qt::MouseButton curr_mouse; // which mouse button is selected
98 	GLArea* current_gla; // the glarea
99 
100 	bool has_track; // to restore the trackball settings
101 
102 
103 	void DrawXORCircle(GLArea * gla, bool doubleDraw); // draws the circle which represents the pen
104 	void getInternFaces(MeshModel & m,list<int> *actual,vector<Vert_Data> * risult, vector<CMeshO::FacePointer> * face_risult,
105 		GLArea * gla,Penn &pen,QPoint &cur, QPoint &prev, GLfloat * pixels,
106 		double mvmatrix[16],double projmatrix[16],GLint viewport[4]);
107 
108 
109 
updateMatrixes()110 	inline void updateMatrixes() {
111 		glGetIntegerv(GL_VIEWPORT, viewport);
112 		glGetDoublev (GL_MODELVIEW_MATRIX, mvmatrix);
113 		glGetDoublev (GL_PROJECTION_MATRIX, projmatrix);
114 	}
115 
116 };
117 
118 
119 class RgbInteractiveEdit
120 {
121 public:
122     /// The tetrahedral mesh type
123     typedef CMeshO TriMeshType;
124     /// The face type
125     typedef TriMeshType::FaceType FaceType;
126     /// The vertex type
127     typedef FaceType::VertexType VertexType;
128     /// The vertex type pointer
129     typedef FaceType::VertexType* VertexPointer;
130     /// The vertex iterator type
131     typedef TriMeshType::VertexIterator VertexIterator;
132     /// The tetra iterator type
133     typedef TriMeshType::FaceIterator FaceIterator;
134     /// The coordinate type
135     typedef FaceType::VertexType::CoordType CoordType;
136     /// The scalar type
137     typedef TriMeshType::VertexType::ScalarType ScalarType;
138     ///the container of tetrahedron type
139     typedef TriMeshType::FaceContainer FaceContainer;
140     ///the container of vertex type
141     typedef TriMeshType::VertContainer VertContainer;
142     ///half edge type
143     typedef TriMeshType::FaceType::EdgeType EdgeType;
144     /// vector of pos
145     typedef std::vector<EdgeType> EdgeVec;
146     /// Face Pointer
147     typedef TriMeshType::FacePointer FacePointer;
148     /// Edge defined by Face and Index
149     typedef EdgeFI<FacePointer> EdgeFIType;
150     /// Topological Operation Class
151     typedef TopologicalOp<CMeshO,RgbInfo::VERTEXC,RgbInfo::FACEC > TopologicalOpC;
152     /// A Point
153     typedef vcg::Point3f Point;
154 	/// RGB Triangle
155     typedef RgbTriangle<CMeshO> RgbTriangleC;
156     /// RGB Vertex
157     typedef RgbVertex<CMeshO> RgbVertexC;
158     /// RGB Edge
159     typedef RgbEdge<CMeshO> RgbEdgeC;
160 
161 	RgbInteractiveEdit(CMeshO& m, RgbInfo& i, TopologicalOpC& to);
162 	~RgbInteractiveEdit();
163 
164 	static bool vertexToRemove(RgbVertexC& v, int* level, double* lenght);
165 	static bool edgeToSplit(RgbTriangleC& t,int index, int* level, double* lenght);
166 
167 	/// Extract the minimum level of incident edges
168 	static int minEdgeLevel(RgbVertexC& v);
169 	/// Extract the maximum level of incident edges
170 	static bool maxEdgeLevel(RgbVertexC& v);
171 
172 	void processVertex(int v, int* level, double* lenght);
173 	void processEdge(int v1, int v2, int* level, double* lenght);
174 
175 	static double maxEdge(RgbVertexC& v);
176 	static double edgeLenght(RgbTriangleC& t, int index);
177 	static bool IsValidVertex(int vp, CMeshO* m,RgbInfo* info, RgbTriangleC* t, int* ti, bool ignoreNew);
178 	static bool IsValidEdge(int v1,int v2, CMeshO* m,RgbInfo* info, RgbTriangleC* t, int* ti);
179 	static void VE(RgbVertexC& v, vector<double>& vv);
180 
181 private:
182 
183 	/// Topological object used
184 	TopologicalOpC* to;
185 	/// Mesh
186 	CMeshO* m;
187 	/// Rgb Information
188 	RgbInfo* info;
189 };
190 
191 }
192 
193 #endif /*INTERACTIVEEDIT_H_*/
194