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 {
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 
vrender::Feedback3DColor::blue
GLfloat blue() const
Definition: Primitive.h:106
vrender::Polygone::initNormal
virtual void initNormal()
Definition: Primitive.cpp:122
vrender::Polygone::bbox
virtual AxisAlignedBox_xyz bbox() const
Definition: Primitive.cpp:112
vrender::Segment::vertex
virtual const Vector3 & vertex(size_t) const
Definition: Primitive.cpp:79
vrender::Point::Point
Point(const Feedback3DColor &f)
Definition: Primitive.cpp:54
vrender::Polygone::nbVertices
virtual size_t nbVertices() const
Definition: Primitive.h:216
vrender::Point::sommet3DColor
virtual const Feedback3DColor & sommet3DColor(size_t) const
Definition: Primitive.cpp:64
Types.h
vrender::Polygone::equation
double equation(const Vector3 &p) const
Definition: Primitive.cpp:117
vrender::Feedback3DColor::pos
const Vector3 & pos() const
Definition: Primitive.h:108
vrender::Vector3::z
double z() const
Definition: Vector3.h:83
vrender::Polygone::_c
double _c
Definition: Primitive.h:234
vrender::Feedback3DColor::alpha
GLfloat alpha() const
Definition: Primitive.h:107
vrender::NVector3
Definition: NVector3.h:75
vrender::FLAT_POLYGON_EPS
const float FLAT_POLYGON_EPS
Definition: Types.h:91
vrender::Vector3::infNorm
double infNorm() const
Infinite norm.
Definition: Vector3.cpp:147
vrender::Segment::bbox
virtual AxisAlignedBox_xyz bbox() const
Definition: Primitive.cpp:84
Primitive.h
vrender::Point::vertex
virtual const Vector3 & vertex(size_t) const
Definition: Primitive.cpp:59
vrender::FLOAT
double FLOAT
Definition: Types.h:80
vrender::Point::bbox
virtual AxisAlignedBox_xyz bbox() const
Definition: Primitive.cpp:74
vrender::Feedback3DColor::green
GLfloat green() const
Definition: Primitive.h:105
vrender::AxisAlignedBox_xyz
AxisAlignedBox< Vector3 > AxisAlignedBox_xyz
Definition: AxisAlignedBox.h:91
vrender::Polygone::sommet3DColor
virtual const Feedback3DColor & sommet3DColor(size_t) const
Definition: Primitive.cpp:92
vrender::Vector3
Definition: Vector3.h:58
vrender::Point::_position_and_color
Feedback3DColor _position_and_color
Definition: Primitive.h:182
vrender::Polygone::anglefactor
double anglefactor
Definition: Primitive.h:232
vrender::Feedback3DColor::red
GLfloat red() const
Definition: Primitive.h:104
vrender::Feedback3DColor
Definition: Primitive.h:94
vrender
Definition: AxisAlignedBox.h:48
vrender::Segment::sommet3DColor
virtual const Feedback3DColor & sommet3DColor(size_t i) const
Definition: Primitive.cpp:69
vrender::AxisAlignedBox::include
void include(const T &v)
Definition: AxisAlignedBox.h:109
vrender::Polygone::_bbox
AxisAlignedBox_xyz _bbox
Definition: Primitive.h:228
vrender::Polygone::_normal
NVector3 _normal
Definition: Primitive.h:235
vrender::Polygone::vertex
virtual const Vector3 & vertex(size_t) const
Definition: Primitive.cpp:97
vrender::AxisAlignedBox< Vector3 >
vrender::Polygone::Polygone
Polygone(const std::vector< Feedback3DColor > &)
Definition: Primitive.cpp:103
vrender::Segment::P2
Feedback3DColor P2
Definition: Primitive.h:200
vrender::Vector3::norm
double norm() const
Norm.
Definition: Vector3.cpp:133
operator<<
ostream & operator<<(ostream &o, const Quaternion &Q)
Definition: quaternion.cpp:528
vrender::Segment::P1
Feedback3DColor P1
Definition: Primitive.h:199
vrender::Polygone::_vertices
std::vector< Feedback3DColor > _vertices
Definition: Primitive.h:229


octovis
Author(s): Kai M. Wurm , Armin Hornung
autogenerated on Thu Apr 3 2025 02:40:44