00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <Plane.hpp>
00021 #include <Cylinder.hpp>
00022 #include <Cone.hpp>
00023 #include <Cube.hpp>
00024
00025 bool Plane::
00026 __inShape(const TinyVector<3, real_t>& p) const
00027 {
00028 const real_t d = __unitNormal * (p-__origine) ;
00029 return (d < 0);
00030 }
00031
00032 Plane::
00033 Plane(const Cube& c,
00034 const size_t& faceNumber)
00035 : Shape(Shape::plane)
00036 {
00037 switch(faceNumber) {
00038 case 0: {
00039 __unitNormal = __normal = TinyVector<3, real_t>(-1,0,0);
00040 __distance = -c.lowerCorner(0);
00041 __origine = __distance*__unitNormal;
00042 break;
00043 }
00044 case 1: {
00045 __unitNormal = __normal = TinyVector<3, real_t>(0,-1,0);
00046 __distance = -c.lowerCorner(1);
00047 __origine = __distance*__unitNormal;
00048 break;
00049 }
00050 case 2: {
00051 __unitNormal = __normal = TinyVector<3, real_t>(0,0,-1);
00052 __distance = -c.lowerCorner(2);
00053 __origine = __distance*__unitNormal;
00054 break;
00055 }
00056 case 3: {
00057 __unitNormal = __normal = TinyVector<3, real_t>(1,0,0);
00058 __distance = c.higherCorner(0);
00059 __origine = __distance*__unitNormal;
00060 break;
00061 }
00062 case 4: {
00063 __unitNormal = __normal = TinyVector<3, real_t>(0,1,0);
00064 __distance = c.higherCorner(1);
00065 __origine = __distance*__unitNormal;
00066 break;
00067 }
00068 case 5: {
00069 __unitNormal = __normal = TinyVector<3, real_t>(0,0,1);
00070 __distance = c.higherCorner(2);
00071 __origine = __distance*__unitNormal;
00072 break;
00073 }
00074 default: {
00075 throw ErrorHandler(__FILE__,__LINE__,
00076 "not implemented",
00077 ErrorHandler::unexpected);
00078 }
00079 }
00080 this->setTransformationsList(c.transformationsList());
00081 }
00082
00083 Plane::
00084 Plane(const Cylinder& c,
00085 const size_t& faceNumber)
00086 : Shape(Shape::plane)
00087 {
00088 switch(faceNumber) {
00089 case 0: {
00090 TinyVector<3, real_t> x = c.__c1 - c.__center;
00091 __unitNormal = __normal = (1./Norm(x)) * x;
00092 __origine = c.__c1;
00093 __distance = __unitNormal*__origine;
00094 break;
00095 }
00096 case 1: {
00097 TinyVector<3, real_t> x = c.__c2 - c.__center;
00098 __unitNormal = __normal = (1./Norm(x)) * x;
00099 __origine = c.__c2;
00100 __distance = __unitNormal*__origine;
00101 break;
00102 }
00103 default: {
00104 throw ErrorHandler(__FILE__,__LINE__,
00105 "not implemented",
00106 ErrorHandler::unexpected);
00107 }
00108 }
00109 this->setTransformationsList(c.transformationsList());
00110 }
00111
00112
00113 Plane::
00114 Plane(const Cone& c,
00115 const size_t& faceNumber)
00116 : Shape(Shape::plane)
00117 {
00118 switch(faceNumber) {
00119 case 0: {
00120 TinyVector<3, real_t> x = c.__center1 - c.__center2;
00121 __unitNormal = __normal = (1./Norm(x)) * x;
00122 __origine = c.__center1;
00123 __distance = __unitNormal*__origine;
00124 break;
00125 }
00126 case 1: {
00127 TinyVector<3, real_t> x = c.__center2 - c.__center1;
00128 __unitNormal = __normal = (1./Norm(x)) * x;
00129 __origine = c.__center2;
00130 __distance = __unitNormal*__origine;
00131 break;
00132 }
00133 default: {
00134 throw ErrorHandler(__FILE__,__LINE__,
00135 "not implemented",
00136 ErrorHandler::unexpected);
00137 }
00138 }
00139 this->setTransformationsList(c.transformationsList());
00140 }
00141
00142 Plane::
00143 Plane(const Vertex& normal,
00144 const real_t& distance)
00145 : Shape(plane),
00146 __normal(normal),
00147 __distance(distance),
00148 __unitNormal(1./Norm(__normal)*__normal),
00149 __origine(distance*__unitNormal)
00150 {
00151 ;
00152 }
00153
00154 Plane::
00155 Plane(const Plane& P)
00156 : Shape(P),
00157 __normal(P.__normal),
00158 __distance(P.__distance),
00159 __unitNormal(P.__unitNormal),
00160 __origine(P.__origine)
00161 {
00162 ;
00163 }
00164
00165 std::ostream& Plane::
00166 __put(std::ostream& s) const
00167 {
00168 s << "plane {\n" << __normal << ',' << __distance << "\n}\n";
00169 return s;
00170 }
00171
00172 ReferenceCounting<Shape> Plane::
00173 __getCopy() const
00174 {
00175 return new Plane(*this);
00176 }