Primitive.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the VRender library.
3  Copyright (C) 2005 Cyril Soler (Cyril.Soler@imag.fr)
4  Version 1.0.0, released on June 27, 2005.
5 
6  http://artis.imag.fr/Members/Cyril.Soler/VRender
7 
8  VRender is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12 
13  VRender is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with VRender; if not, write to the Free Software Foundation, Inc.,
20  51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
21 */
22 
23 /****************************************************************************
24 
25  Copyright (C) 2002-2013 Gilles Debunne. All rights reserved.
26 
27  This file is part of the QGLViewer library version 2.4.0.
28 
29  http://www.libqglviewer.com - contact@libqglviewer.com
30 
31  This file may be used under the terms of the GNU General Public License
32  versions 2.0 or 3.0 as published by the Free Software Foundation and
33  appearing in the LICENSE file included in the packaging of this file.
34  In addition, as a special exception, Gilles Debunne gives you certain
35  additional rights, described in the file GPL_EXCEPTION in this package.
36 
37  libQGLViewer uses dual licensing. Commercial/proprietary software must
38  purchase a libQGLViewer Commercial License.
39 
40  This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
41  WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
42 
43 *****************************************************************************/
44 
45 #include <math.h>
46 #include <assert.h>
47 #include "Primitive.h"
48 #include "Types.h"
49 
50 using namespace vrender ;
51 using namespace std ;
52 
54  : _position_and_color(f)
55 {
56 }
57 
58 const Vector3& Point::vertex(int) const
59 {
60  return _position_and_color.pos() ;
61 }
62 
64 {
65  return _position_and_color ;
66 }
67 
69 {
70  return ( (i&1)==0 )?P1:P2 ;
71 }
72 
74 {
76 }
77 
78 const Vector3& Segment::vertex(int i) const
79 {
80  return ( (i&1)==0 )?P1.pos():P2.pos() ;
81 }
82 
84 {
85  AxisAlignedBox_xyz B(P1.pos());
86  B.include(P2.pos()) ;
87 
88  return B ;
89 }
90 
92 {
93  return _vertices[i % nbVertices()] ;
94 }
95 
96 const Vector3& Polygone::vertex(int i) const
97 {
98  return _vertices[i % nbVertices()].pos() ;
99 }
100 
101 
102 Polygone::Polygone(const vector<Feedback3DColor>& fc)
103  : _vertices(fc)
104 {
105  initNormal() ;
106 
107  for(unsigned int i=0;i<fc.size();i++)
108  _bbox.include(fc[i].pos()) ;
109 }
110 
112 {
113  return _bbox ;
114 }
115 
116 double Polygone::equation(const Vector3& v) const
117 {
118  return v * _normal - _c ;
119 }
120 
122 {
123  FLOAT anglemax = 0.0 ;
124  Vector3 normalmax = Vector3(0.0,0.0,0.0) ;
125  FLOAT v12norm = (vertex(1)-vertex(0)).norm() ;
126 
127  for(unsigned int i=0;i<nbVertices();i++)
128  {
129  Vector3 v1(vertex(i)) ;
130  Vector3 v2(vertex(i+1));
131  Vector3 v3(vertex(i+2)) ;
132 
133  Vector3 normal_tmp((v3-v2)^(v1-v2)) ;
134 
135  FLOAT v32norm = (v3-v2).norm() ;
136 
137  if(normal_tmp.z() > 0)
138  normal_tmp *= -1.0 ;
139 
140  if((v32norm > 0.0)&&(v12norm > 0.0))
141  {
142  double anglemaxtmp = normal_tmp.norm()/v32norm/v12norm ;
143 
144  if(anglemaxtmp > anglemax)
145  {
146  anglemax = anglemaxtmp ;
147  normalmax = normal_tmp ;
148  }
149  }
150 
151  v12norm = v32norm ;
152 
153  if(anglemax > FLAT_POLYGON_EPS) // slight optimization
154  break ;
155  }
156 
157  if(normalmax.infNorm() != 0.0)
158  _normal = NVector3(normalmax) ;
159 
160  anglefactor = anglemax ;
161  _c = _normal*vertex(0) ;
162 }
163 
164 std::ostream& vrender::operator<<(std::ostream& o,const Feedback3DColor& f)
165 {
166  o << "(" << f.pos() << ") + (" << f.red() << "," << f.green() << "," << f.blue() << "," << f.alpha() << ")" << endl ;
167  return o ;
168 }
169 
170 
virtual unsigned int nbVertices() const
Definition: Primitive.h:197
GLfloat alpha() const
Definition: Primitive.h:88
double z() const
Definition: Vector3.h:83
const float FLAT_POLYGON_EPS
Definition: Types.h:71
double equation(const Vector3 &p) const
Definition: Primitive.cpp:116
virtual const Vector3 & vertex(int) const
Definition: Primitive.cpp:58
AxisAlignedBox_xyz _bbox
Definition: Primitive.h:209
virtual const Vector3 & vertex(int) const
Definition: Primitive.cpp:78
NVector3 _normal
Definition: Primitive.h:216
virtual void initNormal()
Definition: Primitive.cpp:121
GLfloat green() const
Definition: Primitive.h:86
virtual const Feedback3DColor & sommet3DColor(int) const
Definition: Primitive.cpp:91
Feedback3DColor _position_and_color
Definition: Primitive.h:163
Polygone(const std::vector< Feedback3DColor > &)
Definition: Primitive.cpp:102
ostream & operator<<(ostream &o, const Quaternion &Q)
Definition: quaternion.cpp:532
virtual unsigned int nbVertices() const
Definition: Primitive.h:158
const Vector3 & pos() const
Definition: Primitive.h:89
virtual AxisAlignedBox_xyz bbox() const
Definition: Primitive.cpp:73
virtual const Vector3 & vertex(int) const
Definition: Primitive.cpp:96
double infNorm() const
Infinite norm.
Definition: Vector3.cpp:146
Point(const Feedback3DColor &f)
Definition: Primitive.cpp:53
virtual AxisAlignedBox_xyz bbox() const
Definition: Primitive.cpp:111
void include(const T &v)
virtual AxisAlignedBox_xyz bbox() const
Definition: Primitive.cpp:83
double FLOAT
Definition: Types.h:60
virtual const Feedback3DColor & sommet3DColor(int) const
Definition: Primitive.cpp:63
AxisAlignedBox< Vector3 > AxisAlignedBox_xyz
GLfloat blue() const
Definition: Primitive.h:87
virtual const Feedback3DColor & sommet3DColor(int i) const
Definition: Primitive.cpp:68
double anglefactor
Definition: Primitive.h:213
double norm() const
Norm.
Definition: Vector3.cpp:132
GLfloat red() const
Definition: Primitive.h:85


octovis
Author(s): Kai M. Wurm , Armin Hornung
autogenerated on Mon Jun 10 2019 14:00:25