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-2014 Gilles Debunne. All rights reserved.
26 
27  This file is part of the QGLViewer library version 2.6.3.
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 
53 
55  : _position_and_color(f)
56 {
57 }
58 
59 const Vector3& Point::vertex(size_t) const
60 {
61  return _position_and_color.pos() ;
62 }
63 
65 {
66  return _position_and_color ;
67 }
68 
70 {
71  return ( (i&1)==0 )?P1:P2 ;
72 }
73 
75 {
77 }
78 
79 const Vector3& Segment::vertex(size_t i) const
80 {
81  return ( (i&1)==0 )?P1.pos():P2.pos() ;
82 }
83 
85 {
86  AxisAlignedBox_xyz B(P1.pos());
87  B.include(P2.pos()) ;
88 
89  return B ;
90 }
91 
93 {
94  return _vertices[i % nbVertices()] ;
95 }
96 
97 const Vector3& Polygone::vertex(size_t i) const
98 {
99  return _vertices[i % nbVertices()].pos() ;
100 }
101 
102 
103 Polygone::Polygone(const vector<Feedback3DColor>& fc)
104  : _vertices(fc)
105 {
106  initNormal() ;
107 
108  for(size_t i=0;i<fc.size();i++)
109  _bbox.include(fc[i].pos()) ;
110 }
111 
113 {
114  return _bbox ;
115 }
116 
117 double Polygone::equation(const Vector3& v) const
118 {
119  return v * _normal - _c ;
120 }
121 
123 {
124  FLOAT anglemax = 0.0 ;
125  Vector3 normalmax = Vector3(0.0,0.0,0.0) ;
126  FLOAT v12norm = (vertex(1)-vertex(0)).norm() ;
127 
128  for(size_t i=0;i<nbVertices();i++)
129  {
130  Vector3 v1(vertex(i)) ;
131  Vector3 v2(vertex(i+1));
132  Vector3 v3(vertex(i+2)) ;
133 
134  Vector3 normal_tmp((v3-v2)^(v1-v2)) ;
135 
136  FLOAT v32norm = (v3-v2).norm() ;
137 
138  if(normal_tmp.z() > 0)
139  normal_tmp *= -1.0 ;
140 
141  if((v32norm > 0.0)&&(v12norm > 0.0))
142  {
143  double anglemaxtmp = normal_tmp.norm()/v32norm/v12norm ;
144 
145  if(anglemaxtmp > anglemax)
146  {
147  anglemax = anglemaxtmp ;
148  normalmax = normal_tmp ;
149  }
150  }
151 
152  v12norm = v32norm ;
153 
154  if(anglemax > FLAT_POLYGON_EPS) // slight optimization
155  break ;
156  }
157 
158  if(normalmax.infNorm() != 0.0)
159  _normal = NVector3(normalmax) ;
160 
161  anglefactor = anglemax ;
162  _c = _normal*vertex(0) ;
163 }
164 
165 std::ostream& vrender::operator<<(std::ostream& o,const Feedback3DColor& f)
166 {
167  o << "(" << f.pos() << ") + (" << f.red() << "," << f.green() << "," << f.blue() << "," << f.alpha() << ")" << endl ;
168  return o ;
169 }
170 
171 
virtual const Vector3 & vertex(size_t) const
Definition: Primitive.cpp:79
GLfloat alpha() const
Definition: Primitive.h:87
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:117
AxisAlignedBox_xyz _bbox
Definition: Primitive.h:208
NVector3 _normal
Definition: Primitive.h:215
virtual void initNormal()
Definition: Primitive.cpp:122
GLfloat green() const
Definition: Primitive.h:85
Feedback3DColor _position_and_color
Definition: Primitive.h:162
Polygone(const std::vector< Feedback3DColor > &)
Definition: Primitive.cpp:103
virtual const Vector3 & vertex(size_t) const
Definition: Primitive.cpp:59
ostream & operator<<(ostream &o, const Quaternion &Q)
Definition: quaternion.cpp:528
virtual const Feedback3DColor & sommet3DColor(size_t) const
Definition: Primitive.cpp:92
const Vector3 & pos() const
Definition: Primitive.h:88
virtual AxisAlignedBox_xyz bbox() const
Definition: Primitive.cpp:74
virtual size_t nbVertices() const
Definition: Primitive.h:196
virtual const Feedback3DColor & sommet3DColor(size_t) const
Definition: Primitive.cpp:64
double infNorm() const
Infinite norm.
Definition: Vector3.cpp:147
Point(const Feedback3DColor &f)
Definition: Primitive.cpp:54
virtual AxisAlignedBox_xyz bbox() const
Definition: Primitive.cpp:112
void include(const T &v)
virtual AxisAlignedBox_xyz bbox() const
Definition: Primitive.cpp:84
double FLOAT
Definition: Types.h:60
AxisAlignedBox< Vector3 > AxisAlignedBox_xyz
GLfloat blue() const
Definition: Primitive.h:86
double anglefactor
Definition: Primitive.h:212
virtual size_t nbVertices() const
Definition: Primitive.h:157
virtual const Feedback3DColor & sommet3DColor(size_t i) const
Definition: Primitive.cpp:69
virtual const Vector3 & vertex(size_t) const
Definition: Primitive.cpp:97
double norm() const
Norm.
Definition: Vector3.cpp:133
GLfloat red() const
Definition: Primitive.h:84


octovis
Author(s): Kai M. Wurm , Armin Hornung
autogenerated on Wed Jun 5 2019 19:26:39