Voreen - Volume Rendering Engine Voreen - Volume Rendering Engine
Voreen - Volume Rendering Engine Westfälische Wilhelms-Universität Münster
  • About
  • Gallery
  • Download
  • Documentation
  • Publications
  • Community

  • Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List

include/voreen/core/datastructures/geometry/pointsegmentlistgeometry.h

00001 /**********************************************************************
00002  *                                                                    *
00003  * Voreen - The Volume Rendering Engine                               *
00004  *                                                                    *
00005  * Copyright (C) 2005-2010 The Voreen Team. <http://www.voreen.org>   *
00006  *                                                                    *
00007  * This file is part of the Voreen software package. Voreen is free   *
00008  * software: you can redistribute it and/or modify it under the terms *
00009  * of the GNU General Public License version 2 as published by the    *
00010  * Free Software Foundation.                                          *
00011  *                                                                    *
00012  * Voreen is distributed in the hope that it will be useful,          *
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of     *
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the       *
00015  * GNU General Public License for more details.                       *
00016  *                                                                    *
00017  * You should have received a copy of the GNU General Public License  *
00018  * in the file "LICENSE.txt" along with this program.                 *
00019  * If not, see <http://www.gnu.org/licenses/>.                        *
00020  *                                                                    *
00021  * The authors reserve all rights not expressly granted herein. For   *
00022  * non-commercial academic use see the license exception specified in *
00023  * the file "LICENSE-academic.txt". To get information about          *
00024  * commercial licensing please contact the authors.                   *
00025  *                                                                    *
00026  **********************************************************************/
00027 
00028 #ifndef VRN_SEGMENTLISTGEOMETRY_H
00029 #define VRN_SEGMENTLISTGEOMETRY_H
00030 
00031 #include "voreen/core/datastructures/geometry/geometry.h"
00032 #include "tgt/glmath.h"
00033 #include <vector>
00034 
00035 namespace voreen {
00036 
00037 template<class T>
00038 class PointSegmentListGeometry : public Geometry {
00039 
00040 public:
00041 
00042     PointSegmentListGeometry() :
00043       Geometry(),
00044       numPoints_(0)
00045     { }
00046 
00047     virtual ~PointSegmentListGeometry() { }
00048 
00049     virtual void render() {
00050         glBegin(GL_POINTS);
00051         for (size_t i=0; i < segmentList_.size(); ++i){
00052             for (size_t j=0; j < segmentList_[i].size(); ++j){
00053                 // assuming data type stored in the segment list is compatible to tgt::vertex
00054                 // if not: template instantiation will fail (compile error)
00055                 tgt::vertex(segmentList_[i][j]);
00056             }
00057         }
00058         glEnd();
00059     }
00060 
00061     void setData(std::vector< std::vector<T> > segmentList) {
00062 
00063         segmentList_ = segmentList;
00064         pointList_.clear();
00065         numPoints_ = 0;
00066         for (size_t i=0; i<segmentList_.size(); ++i) {
00067             numPoints_ += static_cast<int>(segmentList_[i].size());
00068         }
00069 
00070         setHasChanged(true);
00071     }
00072 
00073     void addSegment(std::vector<T> segment) {
00074         segmentList_.push_back(segment);
00075         pointList_.clear();
00076         numPoints_ += static_cast<int>(segment.size());
00077         setHasChanged(true);
00078     }
00079 
00080     const std::vector< std::vector<T> >& getData() const { return segmentList_; }
00081 
00082     const std::vector<T>& getPoints() {
00083 
00084         // generate point list, if not present
00085         if (pointList_.empty() && numPoints_ > 0) {
00086             for (size_t i=0; i<segmentList_.size(); ++i) {
00087                 pointList_.insert(pointList_.end(), segmentList_[i].begin(), segmentList_[i].end());
00088             }
00089         }
00090 
00091         return pointList_;
00092     }
00093 
00094     int getNumSegments() const { return static_cast<int>(segmentList_.size()); }
00095 
00096     int getNumPoints() const { return numPoints_; }
00097 
00098 protected:
00099 
00100     // contains a list of segments, each segment consists of points
00101     std::vector< std::vector<T> > segmentList_;
00102 
00103     // contains the flattened segment list: a list of all points
00104     // is generated on first access
00105     std::vector<T> pointList_;
00106 
00107     int numPoints_;
00108 
00109 };
00110 
00111 typedef PointSegmentListGeometry<tgt::vec3> PointSegmentListGeometryVec3;
00112 
00113 } // namespace
00114 
00115 #endif // VRN_SEGMENTLISTGEOMETRY_H
  • Getting Started
  • Video Tutorials
  • Build Instructions
  • Adding a Module
  • Programming Tutorials
  • API Documentation
  • FAQ
edit