HyperspaceExplorer 0.7.1
Projection.impl.h
00001 /*
00002     Hyperspace Explorer - vizualizing higher-dimensional geometry
00003     Copyright (C) 2010  Lene Preuss <lene.preuss@gmail.com>
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License along
00016     with this program; if not, write to the Free Software Foundation, Inc.,
00017     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00018 
00019 */
00020 
00021 #ifndef PROJECTION_IMPL_H
00022 #define PROJECTION_IMPL_H
00023 
00024 #include "Projection.h"
00025 #include "ViewpointList.impl.h"
00026 #include "ArrayList.impl.h"
00027 
00028 #include <stdexcept>
00029 #include <sstream>
00030 
00031 using VecMath::Vector;
00032 using VecMath::MultiDimensionalVector;
00033 
00041 template <unsigned N, unsigned Nnew, unsigned P, typename NUM, class Policy>
00042 Projection<N, Nnew, P, NUM, Policy>::Projection(
00043 const PointList &viewpoint, const PointList &eye,
00044 const DistanceList &screenDistance, const BoolList &depthCue):
00045     _viewpoint(viewpoint), _eye(eye), _screen_distance(screenDistance), _depth_cue(depthCue) {
00046   checkConsistency();
00047 }
00048 
00054 template <unsigned N, unsigned Nnew, unsigned P, typename NUM, class Policy>
00055 Projection<N, Nnew, P, NUM, Policy>::Projection(NUM scrW, NUM camW, bool depthCue4D) {
00056   _viewpoint = makeOriginViewPointList();
00057   _eye = makeEyePointList(camW);
00058   _screen_distance = makeScreenDistanceList(scrW);
00059   _depth_cue = makeDepthCueList(depthCue4D);
00060   checkConsistency();
00061 }
00062 
00065 template <unsigned N, unsigned Nnew, unsigned P, typename NUM, class Policy>
00066 VecMath::MultiDimensionalVector< VecMath::Vector<Nnew, NUM>, P >
00067 Projection<N, Nnew, P, NUM, Policy>::project(
00068 const VecMath::MultiDimensionalVector< VecMath::Vector<N, NUM>, P > &values) {
00069   Policy p(_viewpoint, _eye, _screen_distance, _depth_cue);
00070   return p.project(values);
00071 }
00072 
00075 template <unsigned N, unsigned Nnew, unsigned P, typename NUM, class Policy>
00076 void Projection<N, Nnew, P, NUM, Policy>::checkConsistency() {
00077   checkDimensions();
00078 }
00079 
00083 template <unsigned N, unsigned Nnew, unsigned P, typename NUM, class Policy>
00084 void Projection<N, Nnew, P, NUM, Policy>::checkDimensions() {
00085 # if Nnew > N
00086 #   error "Tried to project to a higher dimension"
00087 # endif
00088   if (Nnew == N) throw std::logic_error("Explicit specialization should be called");
00089 }
00090 
00091 template <unsigned N, unsigned Nnew, unsigned P, typename NUM, class Policy>
00092 typename Projection<N, Nnew, P, NUM, Policy>::PointList
00093 Projection<N, Nnew, P, NUM, Policy>::makeOriginViewPointList() {
00094   PointList p;
00095   return p;
00096 }
00097 
00098 template <unsigned N, unsigned Nnew, unsigned P, typename NUM, class Policy>
00099 typename Projection<N, Nnew, P, NUM, Policy>::PointList
00100 Projection<N, Nnew, P, NUM, Policy>::makeEyePointList(NUM camW) {
00101   PointList p(camW);
00102   return p;
00103 }
00104 
00105 template <unsigned N, unsigned Nnew, unsigned P, typename NUM, class Policy>
00106 typename Projection<N, Nnew, P, NUM, Policy>::DistanceList
00107 Projection<N, Nnew, P, NUM, Policy>::makeScreenDistanceList(NUM scrW) {
00108   DistanceList p(scrW);
00109   return p;
00110 }
00111 
00112 template <unsigned N, unsigned Nnew, unsigned P, typename NUM, class Policy>
00113 typename Projection<N, Nnew, P, NUM, Policy>::BoolList
00114 Projection<N, Nnew, P, NUM, Policy>::makeDepthCueList(bool depthCue) {
00115   BoolList p(depthCue);
00116   return p;
00117 }
00118 
00119 
00120 template <unsigned N, unsigned Nnew, unsigned P, typename NUM>
00121 VecMath::MultiDimensionalVector< VecMath::Vector<Nnew, NUM>, P >
00122 SimpleProjectionPolicy< N, Nnew, P, NUM >::project(
00123 const VecMath::MultiDimensionalVector< VecMath::Vector<N, NUM>, P > &values) {
00124 
00125   MultiDimensionalVector< Vector<Nnew, NUM>, P > v(values.size());
00126 
00127   for (unsigned i = 0; i < values.size(); ++i) {
00128     SimpleProjectionPolicy<N, Nnew, P-1, NUM> p(_viewpoint, _eye, _screen_distance, _depth_cue);
00129     v[i] = p.project(values[i]);
00130   }
00131 
00132   return v;
00133 
00134 }
00135 
00136 template <unsigned N, unsigned Nnew, typename NUM>
00137 VecMath::MultiDimensionalVector< VecMath::Vector<Nnew, NUM>, 1 >
00138 SimpleProjectionPolicy< N, Nnew, 1, NUM >::project(
00139 const VecMath::MultiDimensionalVector< VecMath::Vector<N, NUM>, 1 > &values) {
00140 
00141   MultiDimensionalVector< Vector<N-1, NUM>, 1 > downprojected(values.size());
00142 
00143   NUM _screen_W = _screen_distance.head();
00144   NUM _camera_W = _eye.head()[N-1];
00145   for (unsigned i = 0; i < values.size(); ++i) {
00146 
00147     NUM projectionFactor = (_screen_W-_camera_W)/(values[i][N-1]-_camera_W);
00148 
00149     for (unsigned j = 0; j < N-1; ++j) downprojected[i][j] = projectionFactor*values[i][j];
00150 
00151   }
00152 
00153   ViewpointList<N-1, Nnew, NUM> v = _viewpoint.tail();
00154   ViewpointList<N-1, Nnew, NUM> e = _eye.tail();
00155   ArrayList<N-Nnew-1, NUM > s = _screen_distance.tail();
00156   ArrayList<N-Nnew-1, bool > d = _depth_cue.tail();
00157   SimpleProjectionPolicy<N-1, Nnew, 1, NUM> p(v, e, s, d);
00158 
00159   return p.project(downprojected);
00160 
00161 }
00162 
00163 #endif // PROJECTION_IMPL_H
 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