bool Box2d<Type>::Intersecte ( const cElTriangleComp & aTri ) const { if ( contains(aTri.P0() ) || contains(aTri.P1() ) || contains(aTri.P2() ) ) return true; Pt2d<Type> Corn[4]; Corners(Corn); for (INT aK=0 ; aK<4 ; aK++) if (aTri.Inside(ToPt2dr(Corn[aK]))) return true; if ( Intersecte(aTri.S01()) || Intersecte(aTri.S12()) || Intersecte(aTri.S20()) ) return true; return false; }
FCE_AxisAlignedBoundingBox FCE_AxisAlignedBoundingBox::Transform( const D3DXMATRIX* pMat ){ D3DXVECTOR3 pCorners[8]; Corners(pCorners); FCE_AxisAlignedBoundingBox ret; for( int iCorner = 0; iCorner < 8; ++iCorner ){ D3DXVECTOR3 transformed; D3DXVec3TransformCoord( &transformed, &(pCorners[iCorner]), pMat ); ret.AddPoints(1, &transformed ); } return ret; }
Box Box::Transform(glm::mat4 transformation) const { Box newBoundingBox; std::vector<glm::vec3> corners; Corners(corners); for (size_t i = 0; i < corners.size(); ++i) { glm::vec3 transformedCorner = glm::vec3(transformation * glm::vec4(corners[i], 1.f)); newBoundingBox.minVertex = glm::min(transformedCorner, newBoundingBox.minVertex); newBoundingBox.maxVertex = glm::max(transformedCorner, newBoundingBox.maxVertex); } return newBoundingBox; }
Box2d<double> Box2d<Type>::BoxImage(const cElMap2D & aMap) const { Pt2d<Type> aC4[4]; Corners(aC4); Pt2dr aP0=aMap(ToPt2dr(aC4[0])); Pt2dr aP1= aP0; for (int aK=1 ; aK<4 ; aK++) { aP0.SetInf(aMap(ToPt2dr(aC4[aK]))); aP1.SetSup(aMap(ToPt2dr(aC4[aK]))); } return Box2d<double>(aP0,aP1); }
void Box2d<Type>::PtsDisc(std::vector<Pt2dr> & aV,INT aNbPts) { aV.clear(); Pt2d<Type> aVCorn[4]; Corners(aVCorn); for (INT aKC=0 ; aKC<4 ; aKC++) { Pt2dr aC0 = ToPt2dr(aVCorn[aKC]); Pt2dr aC1 = ToPt2dr(aVCorn[(aKC+1)%4]); // for (INT aKP=0 ; aKP<= aNbPts ; aKP++) for (INT aKP=0 ; aKP< aNbPts ; aKP++) // Modif MPD { REAL aPds = (aNbPts-aKP) /REAL(aNbPts); aV.push_back(barry(aPds,aC0,aC1)); } } }
std::vector<Pt2d<Type> > Box2d<Type>::Contour() const { Pt2d<Type> aP4[4]; Corners(aP4); return std::vector<Pt2d<Type> >(aP4,aP4+4); }
ImageCommand::ImageCommand(pp::VarDictionary message) { int width = 0; int height = 0; //initialise command variable if (message.HasKey("command")) { if (!message.Get("command").is_string()) throw InvalidCmdException("Command key 'command' is not a string!"); command = message.Get("command").AsString(); } else throw InvalidCmdException("Command key 'command' doesn't exist!"); //initialise all image properties into variables if (message.HasKey("image")) { if (!message.Get("image").is_dictionary()) throw InvalidCmdException("Command key 'image' is not a Dictionary/Object!"); pp::VarDictionary imgDict(message.Get("image")); //initialise corners variable if (imgDict.HasKey("corners")) { if (!imgDict.Get("corners").is_dictionary()) throw InvalidCmdException("Command key 'command' is not a Dictionary/Object!"); corners = Corners(pp::VarDictionary(imgDict.Get("corners"))); } else throw InvalidCmdException("Command key 'corners' doesn't exist!"); //initialise hash variable - changed to unique id if (imgDict.HasKey("id")) { if (imgDict.Get("id").is_double()) { id = round(imgDict.Get("id").AsDouble()); } else if (imgDict.Get("id").is_int()) { id = imgDict.Get("id").AsInt(); } else throw InvalidCmdException("Command key 'id' is not a number!"); } else throw InvalidCmdException("Command key 'id' doesn't exist!"); if (imgDict.HasKey("number")) { if (imgDict.Get("number").is_double()) { number = round(imgDict.Get("number").AsDouble()); } else if (imgDict.Get("number").is_int()) { number = imgDict.Get("number").AsInt(); } else throw InvalidCmdException("Command key 'number' is not a number!"); } else throw InvalidCmdException("Command key 'number' doesn't exist!"); if (imgDict.HasKey("width")) { if (imgDict.Get("width").is_double()) { width = round(imgDict.Get("width").AsDouble()); } else if (imgDict.Get("width").is_int()) { width = imgDict.Get("width").AsInt(); } else throw InvalidCmdException("Command key 'width' is not a number!"); } else throw InvalidCmdException("Command key 'width' doesn't exist!"); if (imgDict.HasKey("height")) { if (imgDict.Get("height").is_double()) { height = round(imgDict.Get("height").AsDouble()); } else if (imgDict.Get("height").is_int()) { height = imgDict.Get("height").AsInt(); } else throw InvalidCmdException("Command key 'height' is not a number!"); } else throw InvalidCmdException("Command key 'height' doesn't exist!"); if (imgDict.HasKey("data")) { if (!imgDict.Get("data").is_array_buffer()) throw InvalidCmdException("Command key 'data' is not an ArrayBuffer!"); pp::VarArrayBuffer arrBuf(imgDict.Get("data")); void* data = arrBuf.Map(); //get pointer to start of contiguous bytes (array); //If the pp::VarDictionary goes completely out of scope, array will likely be deallocated! image = cv::Mat(height, width, CV_8UC4, data); //accepts rows, cols instead of width, height //ArrayBuffer from HTML5 Canvas is RGBA, so 4 channels, 8bit unsigned each } else throw InvalidCmdException("Command key 'data' doesn't exist!"); } else throw InvalidCmdException("Command key 'image' doesn't exist!"); }