HyperspaceExplorer 0.7.1
VertexHolder.impl.h
00001 /*
00002 Hyperspace Explorer - visualizing 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 VertexHolder_IMPL_H
00022 #define VertexHolder_IMPL_H
00023 
00024 #include "VertexHolder.h"
00025 #include "ColorManager.h"
00026 #include "DepthCueUtil.h"
00027 
00028 #include "FunctionValueGrid.h"
00029 #include "TransformationFactory.impl.h"
00030 #include "Transformation.impl.h"
00031 #include "Projection.impl.h"
00032 #include "GridDrawer.impl.h"
00033 
00034 
00035 using VecMath::Vector;
00036 using VecMath::MultiDimensionalVector;
00037 
00038 using std::shared_ptr;
00039 
00040 template <unsigned N, unsigned P, typename NUM>
00041 class VertexHolder<N, P, NUM>::Impl {
00042 
00043 public:
00044 
00045     Impl(VertexHolder<N, P, NUM> *parent): 
00046     X_(), Xtrans_(), Xscr_(), calibration_function(NULL),
00047     parent_(parent) { }
00048 
00049     void applyDepthCue() {
00050         DepthCueUtil::determineExtrema(parent_);
00051         parent_->for_each_vertex_transformed(DepthCueUtil::setDepthCueColor);
00052     }
00053     
00054     function_on_fourspace_vertex getCalibrationFunction() {
00055         if (calibration_function == NULL) return DepthCueUtil::calibrateColor3D;
00056         return calibration_function;
00057     }
00059     VertexGrid<N, P, NUM> X_;
00061     typename VertexGrid<N, P, NUM>::value_storage_type Xtrans_;
00063     MultiDimensionalVector< projected_vertex_type, P > Xscr_;
00064 
00065     function_on_fourspace_vertex calibration_function;
00066     
00067 private: 
00068     
00069     VertexHolder<N, P, NUM> *parent_;
00070     
00071 };
00072 
00074 
00076 template <unsigned N, unsigned P, typename NUM>
00077 VertexHolder<N, P, NUM>::VertexHolder(ParameterMap parms):
00078   Displayable(parms),
00079   pImpl_(new Impl(this)) { }
00080 
00084 template <unsigned N, unsigned P, typename NUM>
00085 void VertexHolder<N, P, NUM>::Transform (const VecMath::Rotation<N, NUM> &R,
00086                                            const vertex_type &T,
00087                                            const vertex_type &scale) {
00088   std::shared_ptr<const Transformation<N, P, NUM> > xform(TransformationFactory::create<N, P, NUM>(R, T, scale));
00089   setXtrans(xform->transform(X()));
00090 }
00091 
00097 template <unsigned N, unsigned P, typename NUM>
00098 void VertexHolder<N, P, NUM>::Project (double ScrW, double CamW, bool DepthCue4D) {
00099   Projection<N, 3, P, NUM> p(ScrW, CamW, DepthCue4D);
00100   setXscr(p.project(Xtrans()));
00101   if (DepthCue4D) pImpl_->applyDepthCue();
00102 }
00103 
00104 template <unsigned N, unsigned P, typename NUM>
00105 void VertexHolder<N, P, NUM>::calibrateColors() {
00106     for_each_vertex(pImpl_->getCalibrationFunction());
00107 }
00108 
00109 template <unsigned N, unsigned P, typename NUM>
00110 unsigned int VertexHolder<N, P, NUM>::getDefinitionSpaceDimensions() {
00111   return P;
00112 }
00113 
00117 template <unsigned N, unsigned P, typename NUM>
00118 void VertexHolder<N, P, NUM>::for_each_vertex(Displayable::function_on_fourspace_vertex apply) {
00119   X().for_each(apply);
00120 }
00121 
00125 template <unsigned N, unsigned P, typename NUM>
00126 void VertexHolder<N, P, NUM>::for_each_vertex_transformed(Displayable::function_on_fourspace_and_transformed_vertex apply) {
00127   VecMath::for_each(X(), Xtrans(), apply);
00128 }
00129 
00133 template <unsigned N, unsigned P, typename NUM>
00134 void VertexHolder<N, P, NUM>::for_each_vertex_transformed_projected(Displayable::function_on_fourspace_transformed_and_projected_vertex apply) {
00135   VecMath::for_each(X(), Xtrans(), Xscr(), apply);
00136 }
00137 
00141 template <unsigned N, unsigned P, typename NUM>
00142 void VertexHolder<N, P, NUM>::for_each_projected(Displayable::function_on_projected_vertex apply) {
00143   Xscr().for_each(apply);
00144 }
00145 
00146 template <unsigned N, unsigned P, typename NUM>
00147 const VecMath::MultiDimensionalVector< VecMath::Vector<N, NUM>, P > &
00148 VertexHolder<N, P, NUM>::X() const {
00149   return pImpl_->X_.getValues();
00150 }
00151 
00155 template <unsigned N, unsigned P, typename NUM>
00156 void VertexHolder<N, P, NUM>::setX(const VertexGrid<N, P, NUM>& x) {
00157   pImpl_->X_ = x;
00158 }
00159 
00160 template <unsigned N, unsigned P, typename NUM>
00161 const VecMath::MultiDimensionalVector< VecMath::Vector<N, NUM>, P > &
00162 VertexHolder<N, P, NUM>::Xtrans() const {
00163   return pImpl_->Xtrans_;
00164 }
00165 
00169 template <unsigned N, unsigned P, typename NUM>
00170 void VertexHolder<N, P, NUM>::setXtrans(const VecMath::MultiDimensionalVector< VecMath::Vector<N, NUM>, P >& x) {
00171   pImpl_->Xtrans_ = x;
00172 }
00173 
00174 template <unsigned N, unsigned P, typename NUM>
00175 const VecMath::MultiDimensionalVector< VecMath::Vector<3, NUM>, P > &
00176 VertexHolder<N, P, NUM>::Xscr() const {
00177   return pImpl_->Xscr_;
00178 }
00179 
00183 template <unsigned N, unsigned P, typename NUM>
00184 void VertexHolder<N, P, NUM>::setXscr(const VecMath::MultiDimensionalVector< VecMath::Vector<3, NUM>, P >& x) {
00185   pImpl_->Xscr_ = x;
00186 }
00187 
00188 template <unsigned N, unsigned P, typename NUM>
00189 const VertexGrid<N, P, NUM> &
00190 VertexHolder<N, P, NUM>::getGrid() const {
00191   return pImpl_->X_;
00192 }
00193 
00194 template <unsigned N, unsigned P, typename NUM>
00195 VertexGrid<N, P, NUM> &
00196 VertexHolder<N, P, NUM>::getGridNonConst() {
00197   return pImpl_->X_;
00198 }
00199 
00203 template <unsigned N, unsigned P, typename NUM>
00204 void
00205 VertexHolder<N, P, NUM>::setColorCalibrationFunction(function_on_fourspace_vertex calibrate) {
00206     pImpl_->calibration_function = calibrate;
00207 }
00208 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends

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