QuadNode.cc 6.93 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
1 2 3
/*===========================================================================*\
 *                                                                           *
 *                              OpenFlipper                                  *
Jan Möbius's avatar
Jan Möbius committed
4
 *      Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen      *
Jan Möbius's avatar
Jan Möbius committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
 *                           www.openflipper.org                             *
 *                                                                           *
 *---------------------------------------------------------------------------*
 *  This file is part of OpenFlipper.                                        *
 *                                                                           *
 *  OpenFlipper is free software: you can redistribute it and/or modify      *
 *  it under the terms of the GNU Lesser General Public License as           *
 *  published by the Free Software Foundation, either version 3 of           *
 *  the License, or (at your option) any later version with the              *
 *  following exceptions:                                                    *
 *                                                                           *
 *  If other files instantiate templates or use macros                       *
 *  or inline functions from this file, or you compile this file and         *
 *  link it with other files to produce an executable, this file does        *
 *  not by itself cause the resulting executable to be covered by the        *
 *  GNU Lesser General Public License. This exception does not however       *
 *  invalidate any other reasons why the executable file might be            *
 *  covered by the GNU Lesser General Public License.                        *
 *                                                                           *
 *  OpenFlipper is distributed in the hope that it will be useful,           *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
 *  GNU Lesser General Public License for more details.                      *
 *                                                                           *
 *  You should have received a copy of the GNU LesserGeneral Public          *
 *  License along with OpenFlipper. If not,                                  *
 *  see <http://www.gnu.org/licenses/>.                                      *
 *                                                                           *
\*===========================================================================*/

/*===========================================================================*\
 *                                                                           *
Jan Möbius's avatar
Jan Möbius committed
37
 *   $Revision$                                                       *
Jan Möbius's avatar
Jan Möbius committed
38 39 40 41
 *   $Author$                                                      *
 *   $Date$                   *
 *                                                                           *
\*===========================================================================*/
Jan Möbius's avatar
 
Jan Möbius committed
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88




//=============================================================================
//
//  CLASS QuadNode - IMPLEMENTATION
//
//=============================================================================


//== INCLUDES =================================================================


#include "QuadNode.hh"
#include "DrawModes.hh"


//== NAMESPACES ============================================================== 


namespace ACG {
namespace SceneGraph {


//== IMPLEMENTATION ========================================================== 


QuadNode::QuadNode( BaseNode*   _parent,
			    std::string _name  )
  : BaseNode(_parent, _name)
{
}
  

//----------------------------------------------------------------------------


QuadNode::~QuadNode() 
{
}


//----------------------------------------------------------------------------


void
89
QuadNode::boundingBox( Vec3d & _bbMin, Vec3d & _bbMax )
Jan Möbius's avatar
 
Jan Möbius committed
90
{
91 92 93 94 95
  Vec3f bbMin(FLT_MAX,FLT_MAX,FLT_MAX);
  Vec3f bbMax(-FLT_MAX,-FLT_MAX,-FLT_MAX);
  
  PointVector::const_iterator p_it  = point_.begin(), p_end = point_.end();
  
Jan Möbius's avatar
 
Jan Möbius committed
96 97
  for ( ; p_it != p_end; ++p_it )
  {
98 99
    bbMin.minimize( *p_it );
    bbMax.maximize( *p_it );
Jan Möbius's avatar
 
Jan Möbius committed
100
  }
101 102 103 104 105 106
  
  Vec3d bbMind = ACG::Vec3d(bbMin);
  Vec3d bbMaxd = ACG::Vec3d(bbMax);
  
  _bbMin.minimize(bbMind);
  _bbMax.maximize(bbMaxd);    
Jan Möbius's avatar
 
Jan Möbius committed
107 108 109 110 111 112
}


//----------------------------------------------------------------------------

  
Jan Möbius's avatar
Jan Möbius committed
113
DrawModes::DrawMode
Jan Möbius's avatar
 
Jan Möbius committed
114
QuadNode::
Jan Möbius's avatar
Jan Möbius committed
115
availableDrawModes() const
Jan Möbius's avatar
 
Jan Möbius committed
116
{
Jan Möbius's avatar
Jan Möbius committed
117 118
  DrawModes::DrawMode drawModes(DrawModes::NONE);

Jan Möbius's avatar
 
Jan Möbius committed
119 120 121 122 123 124 125 126 127 128 129 130 131 132
  drawModes |= DrawModes::WIREFRAME;
  drawModes |= DrawModes::HIDDENLINE;
  drawModes |= DrawModes::SOLID_FLAT_SHADED;
  //  drawModes |= DrawModes::SOLID_FACES_COLORED;

  return drawModes;
}


//----------------------------------------------------------------------------


void
QuadNode::
133
draw(GLState& /* _state */ , const DrawModes::DrawMode& _drawMode)
Jan Möbius's avatar
 
Jan Möbius committed
134 135 136 137
{
  if (_drawMode & DrawModes::WIREFRAME ||
      _drawMode & DrawModes::HIDDENLINE )
  {
138 139
    ACG::GLState::disable(GL_LIGHTING);
    ACG::GLState::shadeModel(GL_FLAT);
Jan Möbius's avatar
 
Jan Möbius committed
140 141 142 143 144 145 146 147 148
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    draw_wireframe();
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  }


  if (_drawMode & DrawModes::SOLID_FLAT_SHADED ||
      _drawMode & DrawModes::HIDDENLINE )
  {
149 150
    ACG::GLState::enable(GL_LIGHTING);
    ACG::GLState::shadeModel(GL_FLAT);
Jan Möbius's avatar
Jan Möbius committed
151
    ACG::GLState::depthRange(0.01, 1.0);
Jan Möbius's avatar
 
Jan Möbius committed
152
    draw_faces();
Jan Möbius's avatar
Jan Möbius committed
153
    ACG::GLState::depthRange(0.0, 1.0);
Jan Möbius's avatar
 
Jan Möbius committed
154 155 156 157
  }

  if (_drawMode & DrawModes::SOLID_FACES_COLORED)
  {
158 159
    ACG::GLState::disable(GL_LIGHTING);
    ACG::GLState::shadeModel(GL_FLAT);
Jan Möbius's avatar
Jan Möbius committed
160
    ACG::GLState::depthRange(0.01, 1.0);
Jan Möbius's avatar
 
Jan Möbius committed
161
    draw_faces();
Jan Möbius's avatar
Jan Möbius committed
162
    ACG::GLState::depthRange(0.0, 1.0);
Jan Möbius's avatar
 
Jan Möbius committed
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
  }
}


//----------------------------------------------------------------------------


void
QuadNode::
draw_vertices()
{
  //  glDrawArrays(GL_POINTS, 0, mesh_.n_vertices());
}


//----------------------------------------------------------------------------


void
QuadNode::draw_faces()
{
  glBegin(GL_QUADS);

  unsigned int i = 0;
  unsigned int j = 0;

  for ( ; i < point_.size(); i += 4, j += 1 )
  {
    glNormal(  normal_[j] );
    
    glVertex( point_[i + 0] );
    glVertex( point_[i + 1] );
    glVertex( point_[i + 2] );
    glVertex( point_[i + 3] );
  }

  glEnd();
}


//----------------------------------------------------------------------------


void
QuadNode::draw_wireframe()
{
  glBegin(GL_QUADS);
  for ( unsigned int i = 0; i < point_.size(); ++i )
    glVertex( point_[i] );
  glEnd();
}


//----------------------------------------------------------------------------


void
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
220
QuadNode::pick( GLState & _state, PickTarget /* _target */  )
Jan Möbius's avatar
 
Jan Möbius committed
221
{
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
222 223
  _state.pick_set_maximum (1);
  _state.pick_set_name (0);
Jan Möbius's avatar
 
Jan Möbius committed
224 225 226 227 228 229 230 231 232 233
  draw_faces();
}


//----------------------------------------------------------------------------

//=============================================================================
} // namespace SceneGraph
} // namespace ACG
//=============================================================================