HyperspaceExplorer 0.7.1
FacePolygon.impl.h
00001 /* 
00002  * File:   SurfaceType.impl.h
00003  * Author: lene
00004  *
00005  * Created on December 18, 2011, 5:07 PM
00006  */
00007 
00008 #ifndef SURFACETYPE_IMPL_H
00009 #define SURFACETYPE_IMPL_H
00010 
00011 #include "FacePolygon.h"
00012 
00013 #include "Util.h"
00014 #include <QDebug>
00015 
00016 template <unsigned D, unsigned N_vertex> 
00017 FacePolygon<D, N_vertex>::FacePolygon() { 
00018     for (unsigned i = 0; i < N_vertex; _vertices[i++] = 0) ; 
00019 }
00020 
00021 template <unsigned D, unsigned N_vertex> 
00022 FacePolygon<D, N_vertex>::FacePolygon(
00023         const VecMath::MultiDimensionalVector< vertex_type, 1 > &original_container,
00024         const vertex_type &v0, const vertex_type &v1,
00025         const vertex_type &v2) { 
00026     _vertices[0] = &v0; _indices[0] = index_of(v0, original_container);
00027     _vertices[1] = &v1; _indices[1] = index_of(v1, original_container);
00028     _vertices[2] = &v2; _indices[2] = index_of(v2, original_container);
00029     for (unsigned i = 3; i < N_vertex; ++i) {
00030         _vertices[i] = 0;
00031         _indices[i] = 0;
00032     }
00033 }
00034 
00035 template <unsigned D, unsigned N_vertex> 
00036 FacePolygon<D, N_vertex>::FacePolygon(
00037         const VecMath::MultiDimensionalVector< vertex_type, 1 > &original_container,
00038         const vertex_type &v0, const vertex_type &v1,
00039                 const vertex_type &v2, const vertex_type &v3) {
00040       _vertices[0] = &v0; _indices[0] = index_of(v0, original_container);
00041       _vertices[1] = &v1; _indices[1] = index_of(v1, original_container);
00042       _vertices[2] = &v2; _indices[2] = index_of(v2, original_container);
00043       _vertices[3] = &v3; _indices[3] = index_of(v3, original_container);
00044       for (unsigned i = 4; i < N_vertex; ++i) {
00045         _vertices[i] = 0;
00046         _indices[i] = 0;
00047       }
00048     }
00049 
00050 template <unsigned D, unsigned N_vertex> 
00051 const typename FacePolygon<D, N_vertex>::vertex_ptr_type &
00052 FacePolygon<D, N_vertex>::operator[](unsigned i) const { 
00053     return _vertices[i]; 
00054 }
00055 
00056 template <unsigned D, unsigned N_vertex> 
00057 unsigned
00058 FacePolygon<D, N_vertex>::index(unsigned i) const { 
00059     return _indices[i];
00060 }
00061 
00062 template <unsigned D, unsigned N_vertex> 
00063 bool
00064 FacePolygon<D, N_vertex>::operator==(const FacePolygon<D, 4> &other) const {
00065     if (N_vertex != 4) return false;
00066     if (!Util::isPermutation(
00067           _indices[0], _indices[1], _indices[2], _indices[3],
00068           other._indices[0], other._indices[1], other._indices[2], other._indices[3])) {
00069         return false;
00070     }
00071     return (_vertices[0] == other._vertices[0] &&
00072               _vertices[1] == other._vertices[1] &&
00073               _vertices[2] == other._vertices[2] &&
00074               _vertices[3] == other._vertices[3]);
00075 }
00076 
00077 template <unsigned D, unsigned N_vertex> 
00078 void
00079 FacePolygon<D, N_vertex>::print() {
00080     for (unsigned i = 0; i < N_vertex; ++i)
00081         std::cerr << _indices[i] << ": " << *(_vertices[i]) << " ";
00082     std::cerr << std::endl;
00083 }
00084 
00085 template <unsigned D, unsigned N_vertex> 
00086 unsigned
00087 FacePolygon<D, N_vertex>::index_of(
00088         const vertex_type &x,
00089         const VecMath::MultiDimensionalVector< vertex_type, 1 > &original_container) {
00090     // assuming that more surfaces have vertices that have just been added
00091     // to the end of original_container
00092     for (int i = original_container.size()-1; i >= 0; --i) {
00093         if (original_container[i] == x) return i;
00094     }
00095     throw std::logic_error("SurfaceType::index_of(): Tried to find the index of a vertex that was not in the container");
00096 }
00097 
00098 
00099 #endif  /* SURFACETYPE_IMPL_H */
00100 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends

Generated on Mon Apr 9 2012 20:25:15 for HyperspaceExplorer 0.7.1 by doxygen 1.7.4  -  Hosted bySourceForge.net Logo