Info.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2005 Imetric 3D GmbH                                    *
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 
00026 #ifndef _PreComp_
00027 # include <iomanip>
00028 # include <ios>
00029 # include <map>
00030 # include <set>
00031 #endif
00032 
00033 #include "Info.h"
00034 #include "Algorithm.h"
00035 #include "Iterator.h"
00036 
00037 #include <Base/Exception.h>
00038 
00039 using namespace MeshCore;
00040 
00041 MeshInfo::MeshInfo (const MeshKernel &rclM)
00042 : _rclMesh(rclM)
00043 {
00044 }
00045 
00046 std::ostream& MeshInfo::GeneralInformation (std::ostream &rclStream) const
00047 {
00048   unsigned long ulCtPt, ulCtEd, ulCtFc;
00049   ulCtPt = _rclMesh.CountPoints();
00050   ulCtFc = _rclMesh.CountFacets();
00051   ulCtEd = _rclMesh.CountEdges();
00052 
00053   rclStream << "Mesh: ["
00054             << ulCtFc << " Faces, ";
00055           if (ulCtEd!=ULONG_MAX)
00056   rclStream << ulCtEd << " Edges, ";
00057           else
00058   rclStream << "Cannot determine number of edges, ";
00059   rclStream << ulCtPt << " Points"
00060             << "]" << std::endl;
00061 
00062   return rclStream;
00063 }
00064 
00065 std::ostream& MeshInfo::DetailedPointInfo (std::ostream& rclStream) const
00066 {
00067   // print points
00068   unsigned long i;
00069   rclStream << _rclMesh.CountPoints() << " Points:" << std::endl;
00070   MeshPointIterator pPIter(_rclMesh), pPEnd(_rclMesh);
00071   pPIter.Begin();
00072   pPEnd.End();
00073   i = 0;
00074 
00075   rclStream.precision(3);
00076   rclStream.setf(std::ios::fixed | std::ios::showpoint | std::ios::showpos);
00077   while (pPIter < pPEnd)
00078   {
00079     rclStream << "P " << std::setw(4) << (i++)       << ": ("
00080                       << std::setw(8) << (*pPIter).x << ", "
00081                       << std::setw(8) << (*pPIter).y << ", "
00082                       << std::setw(8) << (*pPIter).z << ")" << std::endl;
00083     ++pPIter;
00084   }
00085 
00086   return rclStream;
00087 }
00088 
00089 std::ostream& MeshInfo::DetailedEdgeInfo (std::ostream& rclStream) const
00090 {
00091   // print edges
00092   // get edges from facets
00093   std::map<std::pair<unsigned long, unsigned long>, int > lEdges;
00094 
00095   const MeshFacetArray& rFacets = _rclMesh.GetFacets();
00096   MeshFacetArray::_TConstIterator pFIter;
00097   pFIter = rFacets.begin();
00098   while (pFIter < rFacets.end())
00099   {
00100     const MeshFacet& rFacet = *pFIter;
00101     for ( int j=0; j<3; j++ )
00102     {
00103       unsigned long ulPt0 = std::min<unsigned long>(rFacet._aulPoints[j],  rFacet._aulPoints[(j+1)%3]);
00104       unsigned long ulPt1 = std::max<unsigned long>(rFacet._aulPoints[j],  rFacet._aulPoints[(j+1)%3]);
00105       std::pair<unsigned long, unsigned long> cEdge(ulPt0, ulPt1);
00106       lEdges[ cEdge ]++;
00107     }
00108 
00109     pFIter++;
00110   }
00111 
00112   // print edges
00113   rclStream << lEdges.size() << " Edges:" << std::endl;
00114   std::map<std::pair<unsigned long, unsigned long>, int >::const_iterator  pEIter;
00115   pEIter = lEdges.begin();
00116 
00117   rclStream.precision(3);
00118   rclStream.setf(std::ios::fixed | std::ios::showpoint | std::ios::showpos);
00119   unsigned long i=0;
00120   const MeshPointArray& rPoints = _rclMesh.GetPoints();
00121   while (pEIter != lEdges.end())
00122   {
00123     int ct = pEIter->second;
00124     const Base::Vector3f& rP0 = rPoints[ pEIter->first.first ];
00125     const Base::Vector3f& rP1 = rPoints[ pEIter->first.second ];
00126 
00127     rclStream << "E "    << std::setw(4) << (i++) << ": "
00128               << "  P (" << std::setw(8) << rP0.x << ", "
00129                          << std::setw(8) << rP0.y << ", "
00130                          << std::setw(8) << rP0.z << "); "
00131               << "  P (" << std::setw(8) << rP1.x << ", "
00132                          << std::setw(8) << rP1.y << ", "
00133                          << std::setw(8) << rP1.z << "),  B: " << (ct == 2 ? "n" : "y") << std::endl;
00134     pEIter++;
00135   }
00136 
00137   return rclStream;
00138 }
00139 
00140 std::ostream& MeshInfo::DetailedFacetInfo (std::ostream& rclStream) const
00141 {
00142   // print facets
00143   unsigned long i, j;
00144   rclStream << _rclMesh.CountFacets() << " Faces:" << std::endl;
00145   MeshFacetIterator pFIter(_rclMesh), pFEnd(_rclMesh);
00146   pFIter.Begin();
00147   pFEnd.End();
00148   i = 0;
00149 
00150   rclStream.precision(3);
00151   rclStream.setf(std::ios::fixed | std::ios::showpoint | std::ios::showpos);
00152   while (pFIter < pFEnd)
00153   {
00154     rclStream << "F "    << std::setw(4) << (i++) << ":" << std::endl;
00155     rclStream << "  N (" << std::setw(8) << (*pFIter).GetNormal().x << ", "
00156                          << std::setw(8) << (*pFIter).GetNormal().y << ", "
00157                          << std::setw(8) << (*pFIter).GetNormal().z << ")" << std::endl;
00158     for (j = 0; j < 3; j++)
00159     {
00160       rclStream << "  P (" << std::setw(8) << (*pFIter)._aclPoints[j].x << ", "
00161                            << std::setw(8) << (*pFIter)._aclPoints[j].y << ", "
00162                            << std::setw(8) << (*pFIter)._aclPoints[j].z << ")" << std::endl;
00163     }
00164     ++pFIter;
00165   }
00166 
00167   return rclStream;
00168 }
00169 
00170 std::ostream& MeshInfo::DetailedInformation (std::ostream& rclStream) const
00171 {
00172   DetailedPointInfo( rclStream );
00173   DetailedEdgeInfo ( rclStream );
00174   DetailedFacetInfo( rclStream );
00175 
00176   return rclStream;
00177 }
00178 
00179 std::ostream& MeshInfo::InternalPointInfo (std::ostream& rclStream) const
00180 {
00181   // print points
00182   unsigned long i;
00183   rclStream << _rclMesh.CountPoints() << " Points:" << std::endl;
00184   MeshPointIterator pPIter(_rclMesh), pPEnd(_rclMesh);
00185   pPIter.Begin();
00186   pPEnd.End();
00187   i = 0;
00188 
00189   rclStream.precision(3);
00190   rclStream.setf(std::ios::fixed | std::ios::showpoint | std::ios::showpos);
00191   while (pPIter < pPEnd)
00192   {
00193     rclStream << "P " << std::setw(4) << (i++)       << ": ("
00194                       << std::setw(8) << (*pPIter).x << ", "
00195                       << std::setw(8) << (*pPIter).y << ", "
00196                       << std::setw(8) << (*pPIter).z << ")";
00197     if (pPIter->IsValid() == true)
00198       rclStream << std::endl;
00199     else
00200       rclStream << " invalid" << std::endl;
00201     ++pPIter;
00202   }
00203 
00204   return rclStream;
00205 }
00206 
00207 std::ostream& MeshInfo::InternalFacetInfo (std::ostream& rclStream) const
00208 {
00209   // print facets
00210   unsigned long i;
00211   rclStream << _rclMesh.CountFacets() << " Faces:" << std::endl;
00212 
00213   const MeshFacetArray& rFacets = _rclMesh.GetFacets();
00214   MeshFacetArray::_TConstIterator pFIter;
00215   pFIter = rFacets.begin();
00216   i = 0;
00217   while (pFIter < rFacets.end())
00218   {
00219     rclStream << "F " << std::setw(4) << (i++) << ": P ("
00220                       << std::setw(4) << pFIter->_aulPoints[0] << ", "
00221                       << std::setw(4) << pFIter->_aulPoints[1] << ", "
00222                       << std::setw(4) << pFIter->_aulPoints[2] << ")  "
00223              << "N (" << std::setw(4) << pFIter->_aulNeighbours[0] << ", "
00224                       << std::setw(4) << pFIter->_aulNeighbours[1] << ", "
00225                       << std::setw(4) << pFIter->_aulNeighbours[2] << ") ";
00226 
00227     if (pFIter->IsValid() == true)
00228       rclStream << std::endl;
00229     else
00230       rclStream << " invalid" << std::endl;
00231 
00232     pFIter++;
00233   }
00234 
00235   return rclStream;
00236 }
00237 
00238 std::ostream& MeshInfo::InternalInformation (std::ostream& rclStream) const
00239 {
00240   InternalPointInfo( rclStream );
00241   InternalFacetInfo( rclStream );
00242 
00243   return rclStream;
00244 }
00245 
00246 std::ostream& MeshInfo::TopologyInformation (std::ostream& rclStream) const
00247 {
00248     unsigned long index = 0;
00249     const MeshFacetArray& rFAry = _rclMesh.GetFacets();
00250     for (MeshFacetArray::_TConstIterator it = rFAry.begin(); it != rFAry.end(); ++it, ++index) {
00251         rclStream << "F " << std::setw(4) << index << ": P (" 
00252                   << it->_aulPoints[0] << ", "
00253                   << it->_aulPoints[1] << ", "
00254                   << it->_aulPoints[2] << "), N ("
00255                   << it->_aulNeighbours[0] << ", "
00256                   << it->_aulNeighbours[1] << ", "
00257                   << it->_aulNeighbours[2] << ")" << std::endl;
00258     }
00259     
00260     return rclStream;
00261 }

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