Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

gfx/IndexedPoint3Array.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002   Copyright (C)1996 David Jung <opensim@pobox.com>
00003 
00004   This program/file is free software; you can redistribute it and/or modify
00005   it under the terms of the GNU General Public License as published by
00006   the Free Software Foundation; either version 2 of the License, or
00007   (at your option) any later version.
00008   
00009   This program is distributed in the hope that it will be useful,
00010   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012   GNU General Public License for more details. (http://www.gnu.org)
00013   
00014   You should have received a copy of the GNU General Public License
00015   along with this program; if not, write to the Free Software
00016   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017   
00018   $Id: IndexedPoint3Array.cpp 1030 2004-02-11 20:46:17Z jungd $
00019   $Revision: 1.2 $
00020   $Date: 2004-02-11 15:46:17 -0500 (Wed, 11 Feb 2004) $
00021   $Author: jungd $
00022  
00023 ****************************************************************************/
00024 
00025 #include <gfx/IndexedPoint3Array>
00026 #include <gfx/TriangleIterator>
00027 
00028 using gfx::IndexedPoint3Array;
00029 
00030 
00031 
00032 IndexedPoint3Array::IndexedPoint3Array()
00033   : points(0,10), index(0,10)
00034 {
00035 }
00036 
00037 IndexedPoint3Array::IndexedPoint3Array(const array<Point3>& a)
00038   : points(0,a.size()), index(0,a.size())
00039 {
00040   for (Int p=0; p<a.size(); p++)
00041     addPoint(a[p]);
00042   points.trim();
00043 }
00044 
00045 
00046 IndexedPoint3Array::IndexedPoint3Array(const TriangleContainer& tc)
00047 {
00048   TriangleContainer::const_iterator t = tc.begin();
00049   TriangleContainer::const_iterator end = tc.end();
00050   while (t != end) {
00051     const Triangle3& tri(*t);
00052     addPoint(tri[0]);
00053     addPoint(tri[1]);
00054     addPoint(tri[2]);
00055     ++t;
00056   }
00057 }
00058 
00059 
00060 IndexedPoint3Array::IndexedPoint3Array(const IndexedPoint3Array& ipa)
00061   : points(points), index(index)
00062 {
00063 }
00064  
00065 IndexedPoint3Array::~IndexedPoint3Array()
00066 {
00067 }
00068 
00069 Int IndexedPoint3Array::addPoint(const Point3& p)
00070 {
00071   
00072   Int i;
00073   bool found = findPoint(p,i);
00074 
00075     // p already in the array, just add existing index
00076   if (found)
00077     index.at(index.size()) = i;
00078   else {
00079     // p not in the array.  add it and it's index
00080     points.at(points.size()) = p;
00081     index.at(index.size()) = points.size()-1;
00082   }
00083   return index[index.size()-1];
00084 }
00085 
00086 
00087 bool IndexedPoint3Array::findPoint(const Point3& p, Int& index)
00088 {
00089   Int i=0;
00090   while (i < points.size()) {
00091     if (points[i] == p) {
00092       index = i;
00093       return true;
00094     }
00095     ++i;
00096   }
00097   return false;
00098 }
00099 
00100 
00101 Int IndexedPoint3Array::indexOf(const Point3& p) throw(std::invalid_argument)
00102 {
00103   Int index;
00104   if (findPoint(p,index))
00105     return index;
00106   else
00107     throw std::invalid_argument(Exception("Point3 p is not a member of the array"));
00108 }
00109 
00110 
00111 const base::array<base::Point3>& IndexedPoint3Array::getPointArray() const
00112 {
00113   return points;
00114 }
00115 
00116 const base::array<Int>& IndexedPoint3Array::getIndexArray() const
00117 {
00118   return index;
00119 }
00120 

Generated on Thu Jul 29 15:56:19 2004 for OpenSim by doxygen 1.3.6