Points.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) Juergen Riegel         <juergen.riegel@web.de>          *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 
00024 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 # include <math.h>
00027 # include <iostream>
00028 #endif
00029 
00030 #include <Base/Exception.h>
00031 #include <Base/Matrix.h>
00032 #include <Base/Persistence.h>
00033 #include <Base/Stream.h>
00034 #include <Base/Writer.h>
00035 
00036 #include "Points.h"
00037 #include "PointsAlgos.h"
00038 #include "PointsPy.h"
00039 
00040 using namespace Points;
00041 using namespace std;
00042 
00043 TYPESYSTEM_SOURCE(Points::PointKernel, Data::ComplexGeoData);
00044 
00045 std::vector<const char*> PointKernel::getElementTypes(void) const
00046 {
00047     std::vector<const char*> temp;
00048     //temp.push_back("Segment");
00049 
00050     return temp;
00051 }
00052 
00053 unsigned long PointKernel::countSubElements(const char* Type) const
00054 {
00055     return 0;
00056 }
00057 
00058 Data::Segment* PointKernel::getSubElement(const char* Type, unsigned long n) const
00059 {
00060     //unsigned long i = 1;
00061 
00062     //if (strcmp(Type,"Segment") == 0) {
00063     //    // not implemented
00064     //    assert(0);
00065     //    return 0;
00066     //}
00067 
00068     return 0;
00069 }
00070 
00071 void PointKernel::transformGeometry(const Base::Matrix4D &rclMat)
00072 {
00073     std::vector<Base::Vector3f>& kernel = getBasicPoints();
00074     for (std::vector<Base::Vector3f>::iterator it = kernel.begin(); it != kernel.end(); ++it)
00075         *it = rclMat * (*it);
00076 }
00077 
00078 Base::BoundBox3d PointKernel::getBoundBox(void)const
00079 {
00080     Base::BoundBox3d bnd;
00081     for (const_point_iterator it = begin(); it != end(); ++it)
00082         bnd.Add(*it);
00083     return bnd;
00084 }
00085 
00086 void PointKernel::operator = (const PointKernel& Kernel)
00087 {
00088     if (this != &Kernel) {
00089         // copy the mesh structure
00090         setTransform(Kernel._Mtrx);
00091         this->_Points = Kernel._Points;
00092     }
00093 }
00094 
00095 unsigned int PointKernel::getMemSize (void) const
00096 {
00097     return _Points.size() * sizeof(Base::Vector3f);
00098 }
00099 
00100 void PointKernel::Save (Base::Writer &writer) const
00101 {
00102     if (!writer.isForceXML()) {
00103         writer.Stream() << writer.ind()
00104             << "<Points file=\"" << writer.addFile(writer.ObjectName.c_str(), this) << "\" " 
00105             << "mtrx=\"" << _Mtrx.toString() << "\"/>" << std::endl;
00106     }
00107 }
00108 
00109 void PointKernel::SaveDocFile (Base::Writer &writer) const
00110 {
00111     Base::OutputStream str(writer.Stream());
00112     uint32_t uCt = (uint32_t)size();
00113     str << uCt;
00114     // store the data without transforming it and save as float, not double
00115     for (std::vector<Base::Vector3f>::const_iterator it = _Points.begin(); it != _Points.end(); ++it) {
00116         str << it->x << it->y << it->z;
00117     }
00118 }
00119 
00120 void PointKernel::Restore(Base::XMLReader &reader)
00121 {
00122     clear();
00123 
00124     reader.readElement("Points");
00125     std::string file (reader.getAttribute("file") );
00126 
00127     if (!file.empty()) {
00128         // initate a file read
00129         reader.addFile(file.c_str(),this);
00130     }
00131     if (reader.DocumentSchema > 3) {
00132         std::string Matrix (reader.getAttribute("mtrx") );
00133         _Mtrx.fromString(Matrix);
00134     }
00135 }
00136 
00137 void PointKernel::RestoreDocFile(Base::Reader &reader)
00138 {
00139     Base::InputStream str(reader);
00140     uint32_t uCt = 0;
00141     str >> uCt;
00142     _Points.resize(uCt);
00143     for (unsigned long i=0; i < uCt; i++) {
00144         float x, y, z;
00145         str >> x >> y >> z;
00146         _Points[i].Set(x,y,z);
00147     }
00148 }
00149 
00150 void PointKernel::save(const char* file) const
00151 {
00152     //MeshCore::MeshOutput aWriter(_kernel);
00153     //aWriter.SaveAny(file);
00154 }
00155 
00156 void PointKernel::load(const char* file) 
00157 {
00158     PointsAlgos::Load(*this,file);
00159 }
00160 
00161 void PointKernel::save(std::ostream& out) const
00162 {
00163     //kernel.Write(out);
00164 }
00165 
00166 void PointKernel::getFaces(std::vector<Base::Vector3d> &Points,std::vector<Facet> &Topo,
00167                            float Accuracy, uint16_t flags) const
00168 {
00169     unsigned long ctpoints = _Points.size();
00170     Points.reserve(ctpoints);
00171     for (unsigned long i=0; i<ctpoints; i++) {
00172         Points.push_back(this->getPoint(i));
00173     }
00174 }
00175 
00176 // ----------------------------------------------------------------------------
00177 
00178 PointKernel::const_point_iterator::const_point_iterator
00179 (const PointKernel* kernel, std::vector<Base::Vector3f>::const_iterator index)
00180   : _kernel(kernel), _p_it(index)
00181 {
00182     if(_p_it != kernel->_Points.end())
00183     {
00184         Base::Vector3d vertd(_p_it->x, _p_it->y, _p_it->z);
00185         this->_point = _kernel->_Mtrx * vertd;
00186     }
00187 }
00188 
00189 PointKernel::const_point_iterator::const_point_iterator
00190 (const PointKernel::const_point_iterator& fi)
00191   : _kernel(fi._kernel), _point(fi._point), _p_it(fi._p_it)
00192 {
00193 }
00194 
00195 //PointKernel::const_point_iterator::~const_point_iterator()
00196 //{
00197 //}
00198 
00199 PointKernel::const_point_iterator& 
00200 PointKernel::const_point_iterator::operator=(const PointKernel::const_point_iterator& pi)
00201 {
00202     this->_kernel  = pi._kernel;
00203     this->_point = pi._point;
00204     this->_p_it  = pi._p_it;
00205     return *this;
00206 }
00207 
00208 void PointKernel::const_point_iterator::dereference()
00209 {
00210     Base::Vector3d vertd(_p_it->x, _p_it->y, _p_it->z);
00211     this->_point = _kernel->_Mtrx * vertd;
00212 }
00213 
00214 const Base::Vector3d& PointKernel::const_point_iterator::operator*()
00215 {
00216     dereference();
00217     return this->_point;
00218 }
00219 
00220 const Base::Vector3d* PointKernel::const_point_iterator::operator->()
00221 {
00222     dereference();
00223     return &(this->_point);
00224 }
00225 
00226 bool PointKernel::const_point_iterator::operator==(const PointKernel::const_point_iterator& pi) const
00227 {
00228     return (this->_kernel == pi._kernel) && (this->_p_it == pi._p_it);
00229 }
00230 
00231 bool PointKernel::const_point_iterator::operator!=(const PointKernel::const_point_iterator& pi) const
00232 {
00233     return !operator==(pi);
00234 }
00235 
00236 PointKernel::const_point_iterator&
00237 PointKernel::const_point_iterator::operator++()
00238 {
00239     ++(this->_p_it);
00240     return *this;
00241 }
00242 
00243 PointKernel::const_point_iterator
00244 PointKernel::const_point_iterator::operator++(int)
00245 {
00246     PointKernel::const_point_iterator tmp = *this;
00247     ++(this->_p_it);
00248     return tmp;
00249 }
00250 
00251 PointKernel::const_point_iterator&
00252 PointKernel::const_point_iterator::operator--()
00253 {
00254     --(this->_p_it);
00255     return *this;
00256 }
00257 
00258 PointKernel::const_point_iterator
00259 PointKernel::const_point_iterator::operator--(int)
00260 {
00261     PointKernel::const_point_iterator tmp = *this;
00262     --(this->_p_it);
00263     return tmp;
00264 }
00265 
00266 PointKernel::const_point_iterator
00267 PointKernel::const_point_iterator::operator+ (difference_type off) const
00268 {
00269     PointKernel::const_point_iterator tmp = *this;
00270     return (tmp+=off);
00271 }
00272 
00273 PointKernel::const_point_iterator
00274 PointKernel::const_point_iterator::operator- (difference_type off) const
00275 {
00276     PointKernel::const_point_iterator tmp = *this;
00277     return (tmp-=off);
00278 }
00279 
00280 PointKernel::const_point_iterator&
00281 PointKernel::const_point_iterator::operator+=(difference_type off)
00282 {
00283     (this->_p_it) += off;
00284     return *this;
00285 }
00286 
00287 PointKernel::const_point_iterator&
00288 PointKernel::const_point_iterator::operator-=(difference_type off)
00289 {
00290     (this->_p_it) -= off;
00291     return *this;
00292 }
00293 
00294 PointKernel::difference_type
00295 PointKernel::const_point_iterator::operator- (const PointKernel::const_point_iterator& right) const
00296 {
00297     return this->_p_it - right._p_it;
00298 }

Generated on Wed Nov 23 19:00:27 2011 for FreeCAD by  doxygen 1.6.1