VCG Library
Loading...
Searching...
No Matches
component_ep.h
1/****************************************************************************
2* VCGLib o o *
3* Visual and Computer Graphics Library o o *
4* _ O _ *
5* Copyright(C) 2004-2016 \/)\/ *
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 __VCG_TRI_UPDATE_EDGES
24#define __VCG_TRI_UPDATE_EDGES
25
26#include <vcg/space/plane3.h>
27
28namespace vcg {
29namespace tri {
30
32
34 template <class ComputeMeshType>
36 {
37
38 public:
39 typedef ComputeMeshType MeshType;
40 typedef typename MeshType::VertexType VertexType;
41 typedef typename MeshType::VertexPointer VertexPointer;
42 typedef typename MeshType::VertexIterator VertexIterator;
43 typedef typename MeshType::FaceType FaceType;
44 typedef typename MeshType::FacePointer FacePointer;
45 typedef typename MeshType::FaceIterator FaceIterator;
46 typedef typename MeshType::FaceType::CoordType::ScalarType ScalarType;
47
48 static void ComputeEdgePlane(FaceType &f)
49 {
50 f.Flags() = f.Flags() & (~(FaceType::NORMX|FaceType::NORMY|FaceType::NORMZ));
51
52 // Primo calcolo degli edges
53 f.Edge(0) = f.V(1)->P(); f.Edge(0) -= f.V(0)->P();
54 f.Edge(1) = f.V(2)->P(); f.Edge(1) -= f.V(1)->P();
55 f.Edge(2) = f.V(0)->P(); f.Edge(2) -= f.V(2)->P();
56 // Calcolo di plane
57 f.Plane().SetDirection(f.Edge(0)^f.Edge(1));
58 f.Plane().SetOffset(f.Plane().Direction().dot(f.V(0)->P()));
59 f.Plane().Normalize();
60 // Calcolo migliore proiezione
61 ScalarType nx = math::Abs(f.Plane().Direction()[0]);
62 ScalarType ny = math::Abs(f.Plane().Direction()[1]);
63 ScalarType nz = math::Abs(f.Plane().Direction()[2]);
64 ScalarType d;
65 if(nx>ny && nx>nz) { f.Flags() |= FaceType::NORMX; d = 1/f.Plane().Direction()[0]; }
66 else if(ny>nz) { f.Flags() |= FaceType::NORMY; d = 1/f.Plane().Direction()[1]; }
67 else { f.Flags() |= FaceType::NORMZ; d = 1/f.Plane().Direction()[2]; }
68
69 // Scalatura spigoli
70 f.Edge(0)*=d;
71 f.Edge(1)*=d;
72 f.Edge(2)*=d;
73 }
74
75 static void Set(ComputeMeshType &m)
76 {
77 if(!FaceType::HasEdgePlane()) throw vcg::MissingComponentException("PerFaceEdgePlane");
78 for(FaceIterator f = m.face.begin(); f!=m.face.end(); ++f)
79 if(!(*f).IsD())
80 ComputeEdgePlane(*f);
81 }
82
83 }; // end class
84
85} // End namespace
86} // End namespace
87
88
89#endif
This class is used to compute or update the precomputed data used to efficiently compute point-face d...
Definition: component_ep.h:36
Definition: color4.h:30