UniformCartesianArray.hpp

00001 #ifndef __FIBER__UNIFORMCARTESIANARRAY_HPP
00002 #define __FIBER__UNIFORMCARTESIANARRAY_HPP
00003 
00004 #include "DirectProductArray.hpp"
00005 #include <eagle/PhysicalSpace.hpp>
00006 #include <aerie/BoundingBox.hpp>
00007 
00008 namespace Fiber
00009 {
00010 
00014 class   FIELD_API       UniformCartesianArray : public  LinearDirectProductMemArray<Eagle::point3>
00015 {
00017         Eagle::point3 MakeDeltaPoint(const Eagle::tvector3&what)
00018         {
00019                 return Eagle::point3(0.0,0.0,0.0) + what;
00020         } 
00021 
00022         Eagle::point3 DeltaPoint(const Eagle::tvector3&what, const MultiIndex<3>&divisor)
00023         {
00024         Eagle::point3 retval; 
00025                 for(int i=0; i<3; i++)
00026                 {
00027                         if (divisor[i]<2)
00028                                 throw Exception( i, divisor[i]);
00029 
00030                         retval[i] = what[i] / (divisor[i]-1);
00031                 }
00032                 return retval;
00033         }
00034 
00035 public: 
00036         struct  Exception : std::exception
00037         {
00038                 int     dimension;
00039                 index_t value;
00040 
00041                 Exception(int Dimension, index_t Value)
00042                 : dimension( Dimension)
00043                 , value(Value)
00044                 {}
00045 
00046                 override const char*what() const throw()
00047                 {
00048                         return "UniformCartesianArray: Specified Grid has less than two points, can't construct such.";
00049                 }               
00050         };
00051 
00057         UniformCartesianArray(const Eagle::point3&start, const MultiIndex<3>&dims, 
00058                               const Eagle::point3&end,
00059                               const MemBase::Creator_t&C = MemCore::NullPtr() ) throw (const Exception&)
00060         : MemBase(C)
00061         , LinearDirectProductMemArray<Eagle::point3>(dims, start, DeltaPoint(end-start, dims), C )
00062         {}
00063 
00069         UniformCartesianArray(const Eagle::BoundingBox&BBox, const MultiIndex<3>&dims, const MemBase::Creator_t&C = MemCore::NullPtr() ) throw (const Exception&)
00070         : MemBase(C)
00071         , LinearDirectProductMemArray<Eagle::point3>(dims, BBox.mincoord(), DeltaPoint(BBox.maxcoord()-BBox.mincoord(), dims), C )
00072         {} 
00073 
00078         UniformCartesianArray(const MultiIndex<3>&dims, const Eagle::point3&start,
00079                               const Eagle::tvector3&delta, const MemBase::Creator_t&C = MemCore::NullPtr() )
00080         : MemBase(C)
00081         , LinearDirectProductMemArray<Eagle::point3>(dims, start, MakeDeltaPoint(delta), C )
00082         {} 
00083 
00089         UniformCartesianArray(const MultiIndex<3>&dims, const Eagle::point3&start,
00090                               const Eagle::point3&delta, const MemBase::Creator_t&C = MemCore::NullPtr() )
00091         : MemBase(C)
00092         , LinearDirectProductMemArray<Eagle::point3>(dims, start, delta, C)
00093         {}
00094 
00096         ~UniformCartesianArray(); 
00097 
00102         Eagle::tvector3 cell_diagonal() const
00103         {
00104                 return Delta() - Eagle::point3(0,0,0);
00105         }
00106 };
00107 
00108 
00109 } // namespace Fiber
00110 
00111 #endif // __FIBER__UNIFORMCARTESIANARRAY_HPP
00112