triangle3D.cpp

Go to the documentation of this file.
00001 
00015 #include <dlrGeometry/triangle3D.h>
00016 #include <dlrNumeric/utilities.h>
00017 
00018 namespace dnum = dlr::numeric;
00019 
00020 namespace dlr {
00021 
00022   namespace geometry {
00023     
00024     // This constructor initializes the triangle using three points.
00025     Triangle3D::
00026     Triangle3D(const Vector3D& vertex0,
00027             const Vector3D& vertex1,
00028             const Vector3D& vertex2)
00029       : m_vertex0(vertex0),
00030         m_vertex1(vertex1),
00031         m_vertex2(vertex2)
00032     {
00033       // Empty.
00034     }
00035 
00036     
00037     // The copy constructor deep copies its argument.
00038     Triangle3D::
00039     Triangle3D(const Triangle3D& source)
00040       : m_vertex0(source.m_vertex0),
00041         m_vertex1(source.m_vertex1),
00042         m_vertex2(source.m_vertex2)
00043     {
00044       // Empty.
00045     }
00046 
00047 
00048     // The assignment operator deep copies its argument.
00049     Triangle3D&
00050     Triangle3D::
00051     operator=(const Triangle3D& source)
00052     {
00053       if(&source != this) {
00054         m_vertex0 = source.m_vertex0;
00055         m_vertex1 = source.m_vertex1;
00056         m_vertex2 = source.m_vertex2;
00057       }
00058       return *this;
00059     }
00060 
00061 
00062     /* ======= Non-member functions. ======= */
00063 
00064     std::ostream&
00065     operator<<(std::ostream& stream, const Triangle3D& triangle)
00066     {
00067       stream << "Triangle3D { "
00068              << triangle.getVertex0() << ", "
00069              << triangle.getVertex1() << ", "
00070              << triangle.getVertex2() << " }";
00071       return stream;
00072     }
00073 
00074 
00075     std::istream&
00076     operator>>(std::istream& stream, Triangle3D& triangle)
00077     {
00078       // If stream is in a bad state, we can't read from it.
00079       if (!stream){
00080         return stream;
00081       }
00082     
00083       // It's a lot easier to use a try block than to be constantly
00084       // testing whether the IO has succeeded, so we tell inputStream to
00085       // complain if anything goes wrong.
00086       std::ios_base::iostate oldExceptionState = stream.exceptions();
00087       stream.exceptions(
00088         std::ios_base::badbit | std::ios_base::failbit | std::ios_base::eofbit);
00089 
00090       // Now on with the show.
00091       try{
00092         dnum::Vector3D vertex0;
00093         dnum::Vector3D vertex1;
00094         dnum::Vector3D vertex2;
00095         
00096         // Construct an InputStream instance so we can use our
00097         // convenience functions.
00098         dlr::common::InputStream inputStream(
00099           stream, dlr::common::InputStream::SKIP_WHITESPACE);
00100 
00101         inputStream.expect("Triangle3D");
00102         inputStream.expect("{");
00103         inputStream >> vertex0;
00104         inputStream.expect(",");
00105         inputStream >> vertex1;
00106         inputStream.expect(",");
00107         inputStream >> vertex2;
00108         inputStream.expect("}");
00109 
00110         triangle.setValue(vertex0, vertex1, vertex2);
00111         
00112       } catch(std::ios_base::failure) {
00113         // Empty
00114       }
00115       stream.exceptions(oldExceptionState);
00116       return stream;
00117     }
00118 
00119     
00120   } // namespace utilities
00121     
00122 } // namespace dlr

Generated on Wed Nov 25 11:45:25 2009 for dlrGeometry Utility Library by  doxygen 1.5.8