Developer Documentation
PlaneType.cc
1 /*===========================================================================*\
2  * *
3  * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40 \*===========================================================================*/
41 
42 #include "PlaneType.hh"
43 
44 namespace ACG {
45 namespace Geometry {
46 
47 
48 void Plane::setPlane(const ACG::Vec3d& _position, const ACG::Vec3d& _xDirection, const ACG::Vec3d& _yDirection)
49 {
50  position = _position;
51  xDirection = _xDirection;
52  yDirection = _yDirection;
53  normal = (_xDirection % _yDirection).normalize();
54 }
55 
56 //----------------------------------------------------------------
57 
58 void Plane::setPlane(const ACG::Vec3d& _position, const ACG::Vec3d& _normal)
59 {
60 
61  //find a non zero component
62  int comp = -1;
63  for (int i=0; i < 3; i++)
64  if ( _normal[i] != 0.0 ){
65  comp = i;
66  break;
67  }
68 
69  if (comp == -1){
70  std::cerr << "PlaneNode: normal is invalid!" << std::endl;
71  return;
72  }
73 
74  //compute orthogonal vectors in the plane
75  xDirection[comp] = (-_normal[ (comp + 1) % 3 ] - _normal[(comp + 2) % 3]) / _normal[comp];
76  xDirection[ (comp + 1) % 3 ] = 1;
77  xDirection[ (comp + 2) % 3 ] = 1;
78  xDirection = xDirection.normalize();
79 
80  yDirection = _normal % xDirection;
81  yDirection = yDirection.normalize();
82 
83  position = _position;
84  normal = _normal;
85 }
86 
87 //----------------------------------------------------------------
88 
90 {
91  position = _mat.transform_point(position);
92  xDirection = _mat.transform_vector(xDirection);
93  yDirection = _mat.transform_vector(yDirection);
94 
95  normal = (xDirection % yDirection).normalize();
96 }
97 
98 //----------------------------------------------------------------
99 
100 void Plane::setSize(double _xDirection, double _yDirection)
101 {
102  xDirection = xDirection.normalize() * _xDirection;
103  yDirection = yDirection.normalize() * _yDirection;
104 }
105 
106 }} // namespaces
107 
108 //=============================================================================
Namespace providing different geometric functions concerning angles.
VectorT< T, 3 > transform_point(const VectorT< T, 3 > &_v) const
transform point (x&#39;,y&#39;,z&#39;,1) = M * (x,y,z,1)
void transform(const ACG::Matrix4x4d &_mat)
Transform the plane with given matrix.
Definition: PlaneType.cc:89
void setPlane(const ACG::Vec3d &_position, const ACG::Vec3d &_xDirection, const ACG::Vec3d &)
Set plane.
Definition: PlaneType.cc:48
VectorT< T, 3 > transform_vector(const VectorT< T, 3 > &_v) const
transform vector (x&#39;,y&#39;,z&#39;,0) = A * (x,y,z,0)
void setSize(double _xDirection, double _yDirection)
Set plane size.
Definition: PlaneType.cc:100
auto normalize() -> decltype(*this/=std::declval< VectorT< S, DIM >>().norm())
Definition: Vector11T.hh:434