1 /****************************************************************************
2 * MeshLab                                                           o o     *
3 * A versatile mesh processing toolbox                             o     o   *
4 *                                                                _   O  _   *
5 * Copyright(C) 2005                                                \/)\/    *
6 * Visual Computing Lab                                            /\/|      *
7 * ISTI - Italian National Research Council                           |      *
8 *                                                                    \      *
9 * All rights reserved.                                                      *
10 *                                                                           *
11 * This program is free software; you can redistribute it and/or modify      *
12 * it under the terms of the GNU General Public License as published by      *
13 * the Free Software Foundation; either version 2 of the License, or         *
14 * (at your option) any later version.                                       *
15 *                                                                           *
16 * This program is distributed in the hope that it will be useful,           *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
19 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)          *
20 * for more details.                                                         *
21 *                                                                           *
22 ****************************************************************************/
23 #ifndef UVFACETEXTURE_H_
24 #define UVFACETEXTURE_H_
25 
26 #include <src/QuadTree/QuadTreeLeaf.h>
27 
28 /*
29  * The UVFaceTexture class stores UV texture information of a face.
30  * It also ofers functions to check if a uv point lies inside the
31  * 2D triangle generated by the 3 uv coordinates.
32  */
33 
34 class UVFaceTexture: public QuadTreeLeaf{
35 public:
36 
37 
38 	int type;					//0 = camera; 1 = program
39 	double faceAngleToCamera;	//angle of the face to the camera
40 	double u[3];
41 	double v[3];
42 	int faceIndex;				//index of the 3D face of the MeshModel
43 	int textureindex;			//index of the corresponding texture
44 
UVFaceTexture()45 	UVFaceTexture(){
46 	}
~UVFaceTexture()47 	~UVFaceTexture(){
48 
49 	}
50 	/*
51 	 * Calculates the barycentric coordinate (a,b,c) of the uv triangle for the uv
52 	 * coordinate (eu,ev). If d is 0.0 the uv coordinate liese inside the uv triangle.
53 	 * If not d is equal 1.0.
54 	 */
55 	void getBarycentricCoordsForUV(double eu,double ev,double& a,double& b,double& c,double& d);
56 
57 	/*
58 	 * Gets the uv (eu,ev) coordinates of the triangle for a given barycentric
59 	 * cordinate (a,b,c).
60 	 */
61 	void getUVatBarycentricCoords(double &eu,double &ev,double a,double b,double c);
62 
63 	/*
64 	 * Checks if a part of the uv triangle lies in the rectangle spanned by the
65 	 * starting point (x,y) the width w and the height h.
66 	 */
67 	virtual bool isInside(double x, double y, double w, double h);
68 
69 	/*
70 	 * Checks if the 2D point (x,y) lies inside the uv triangle
71 	 */
72 	virtual bool isInside(double x, double y);
73 
74 private:
75 	/*
76 	 * Checks if the 2D line segment from p1 to p2 intersects with
77 	 * one of the sides of the 2D trinagle generated by the 3 uv coordinates.
78 	 */
79 	bool intersection(double *p1,double *p2);
80 
81 	/*
82 	 * Checks if there is an intersection of the two 2D line segments p1->p2 and p3->p4.
83 	 */
84 	bool intersectionOfTwoLines(double *p1,double *p2,double *p3, double *p4);
85 };
86 
87 #endif /*UVFACETEXTURE_H_*/
88