int main() { //RigidBody body1(5.0f,4.f,2.f,1.0f); //RigidBody body2(5.0f, 4.f, 2.f, 1.0f); SimulationWorld world1(400.f, 400.f); world1.simulate(1.f); }
std::vector< std::shared_ptr<Carta::Lib::RegionInfo> > RegionCASA::_loadRegion( const QString & fname, std::shared_ptr<Carta::Lib::Image::ImageInterface> imagePtr ){ std::vector<std::shared_ptr<Carta::Lib::RegionInfo> > regionInfos; casa::String fileName( fname.toStdString().c_str() ); CCImageBase * base = dynamic_cast<CCImageBase*>( imagePtr.get() ); if ( base ){ Carta::Lib::Image::MetaDataInterface::SharedPtr metaPtr = base->metaData(); CCMetaDataInterface* metaData = dynamic_cast<CCMetaDataInterface*>(metaPtr.get()); if ( metaData ){ std::shared_ptr<casa::CoordinateSystem> cs = metaData->getCoordinateSystem(); std::vector < int > dimensions = imagePtr->dims(); int dimCount = dimensions.size(); casa::IPosition shape(dimCount); for ( int i = 0; i < dimCount; i++ ){ shape[i] = dimensions[i]; } casa::RegionTextList regionList( fileName, *cs.get(), shape ); casa::Vector<casa::AsciiAnnotationFileLine> aaregions = regionList.getLines(); int regionCount = aaregions.size(); for ( int i = 0; i < regionCount; i++ ){ if ( aaregions[i].getType() != casa::AsciiAnnotationFileLine::ANNOTATION ){ continue; } casa::CountedPtr<const casa::AnnotationBase> ann = aaregions[i].getAnnotationBase(); std::shared_ptr<Carta::Lib::RegionInfo> rInfo( new Carta::Lib::RegionInfo()); casa::Vector<casa::MDirection> directions = ann->getConvertedDirections(); casa::AnnotationBase::Direction points = ann->getDirections(); std::vector<std::pair<double,double> > corners = _getPixelVertices( points, *cs.get(), directions ); int annType = ann->getType(); switch( annType ){ case casa::AnnotationBase::RECT_BOX : { _addCorners( rInfo, corners ); rInfo->setRegionType( Carta::Lib::RegionInfo::RegionType::Polygon ); } break; case casa::AnnotationBase::ELLIPSE : { rInfo->setRegionType( Carta::Lib::RegionInfo::RegionType::Ellipse ); const casa::AnnEllipse* ellipse = dynamic_cast<const casa::AnnEllipse*>( ann.get() ); casa::Int directionIndex = cs->findCoordinate(casa::Coordinate::Type::DIRECTION ); casa::MDirection::Types csType = casa::MDirection::EXTRA; if ( directionIndex >= 0 ){ casa::DirectionCoordinate dCoord = cs->directionCoordinate(directionIndex); csType = dCoord.directionType(); } if ( csType == casa::MDirection::EXTRA ){ qWarning( "Unable to complete elliptical region, unspecified direction type."); continue; } // convert to the viewer's world coordinates... <mdirection> casa::MDirection dir_center = casa::MDirection::Convert(ellipse->getCenter( ), csType)(); casa::Vector<double> center = dir_center.getAngle("rad").getValue( ); // 90 deg around 0 & 180 deg const double major_radius = ellipse->getSemiMajorAxis().getValue("rad"); const double minor_radius = ellipse->getSemiMinorAxis().getValue("rad"); const double pos_angle = ellipse->getPositionAngle( ).getValue("deg"); const bool x_is_major = ((pos_angle > 45.0 && pos_angle < 135.0) || (pos_angle > 225.0 && pos_angle < 315.0)); const double xradius = (x_is_major ? major_radius : minor_radius); const double yradius = (x_is_major ? minor_radius : major_radius); casa::Vector<casa::Double> world0(2, 0); casa::Vector<casa::Double> world1(2, 0); world0[0] = center[0] - xradius; world0[1] = center[1] - yradius; world1[0] = center[0] + xradius; world1[1] = center[1] + yradius; casa::Vector<casa::Double> pixel0(2, 0); casa::Vector<casa::Double> pixel1(2, 0); std::vector<std::pair<double,double> > ellipseCorners(2); const casa::CoordinateSystem ellipsCoord = ellipse->getCsys(); bool firstConvert = ellipsCoord.directionCoordinate().toPixel( pixel0, world0 ); bool secondConvert = ellipsCoord.directionCoordinate().toPixel( pixel1, world1 ); if ( firstConvert && secondConvert ){ ellipseCorners[0] = std::pair<double,double>( pixel0[0], pixel0[1] ); ellipseCorners[1] = std::pair<double,double>( pixel1[0], pixel1[1] ); _addCorners( rInfo, ellipseCorners ); } else { qDebug() << "Problem storing ellipse corners: "<<ellipsCoord.errorMessage().c_str(); } } break; case casa::AnnotationBase::POLYGON : { _addCorners( rInfo, corners ); rInfo->setRegionType( Carta::Lib::RegionInfo::RegionType::Polygon ); } break; //Point???? case casa::AnnotationBase::SYMBOL : { _addCorners( rInfo, corners ); rInfo->setRegionType( Carta::Lib::RegionInfo::RegionType::Polygon ); } break; } regionInfos.push_back( rInfo ); } } } return regionInfos; }
TEST(WorldDiff, SetWorld) { collision_detection::WorldPtr world1(new collision_detection::World); collision_detection::WorldPtr world2(new collision_detection::World); collision_detection::WorldDiff diff1(world1); collision_detection::WorldDiff diff1b(world1); collision_detection::WorldDiff diff2(world2); collision_detection::WorldDiff::const_iterator it; shapes::ShapePtr ball(new shapes::Sphere(1.0)); shapes::ShapePtr box(new shapes::Box(1,2,3)); shapes::ShapePtr cyl(new shapes::Cylinder(4,5)); world1->addToObject("objA1", ball, Eigen::Affine3d::Identity()); world1->addToObject("objA2", ball, Eigen::Affine3d::Identity()); world1->addToObject("objA3", ball, Eigen::Affine3d::Identity()); world2->addToObject("objB1", box, Eigen::Affine3d::Identity()); world2->addToObject("objB2", box, Eigen::Affine3d::Identity()); world2->addToObject("objB3", box, Eigen::Affine3d::Identity()); EXPECT_EQ(3, diff1.getChanges().size()); EXPECT_EQ(3, diff1b.getChanges().size()); EXPECT_EQ(3, diff2.getChanges().size()); diff1b.clearChanges(); EXPECT_EQ(3, diff1.getChanges().size()); EXPECT_EQ(0, diff1b.getChanges().size()); EXPECT_EQ(3, diff2.getChanges().size()); diff1.setWorld(world2); EXPECT_EQ(6, diff1.getChanges().size()); EXPECT_EQ(0, diff1b.getChanges().size()); EXPECT_EQ(3, diff2.getChanges().size()); it = diff1.getChanges().find("objA1"); EXPECT_NE(diff1.end(), it); EXPECT_EQ(collision_detection::World::DESTROY, it->second); it = diff1.getChanges().find("objA2"); EXPECT_NE(diff1.end(), it); EXPECT_EQ(collision_detection::World::DESTROY, it->second); it = diff1.getChanges().find("objA2"); EXPECT_NE(diff1.end(), it); EXPECT_EQ(collision_detection::World::DESTROY, it->second); it = diff1.getChanges().find("objB1"); EXPECT_NE(diff1.end(), it); EXPECT_EQ(collision_detection::World::CREATE | collision_detection::World::ADD_SHAPE, it->second); it = diff1.getChanges().find("objB2"); EXPECT_NE(diff1.end(), it); EXPECT_EQ(collision_detection::World::CREATE | collision_detection::World::ADD_SHAPE, it->second); it = diff1.getChanges().find("objB3"); EXPECT_NE(diff1.end(), it); EXPECT_EQ(collision_detection::World::CREATE | collision_detection::World::ADD_SHAPE, it->second); diff1b.setWorld(world2); EXPECT_EQ(6, diff1.getChanges().size()); EXPECT_EQ(6, diff1b.getChanges().size()); EXPECT_EQ(3, diff2.getChanges().size()); it = diff1b.getChanges().find("objA1"); EXPECT_NE(diff1b.end(), it); EXPECT_EQ(collision_detection::World::DESTROY, it->second); it = diff1b.getChanges().find("objA2"); EXPECT_NE(diff1b.end(), it); EXPECT_EQ(collision_detection::World::DESTROY, it->second); it = diff1b.getChanges().find("objA2"); EXPECT_NE(diff1b.end(), it); EXPECT_EQ(collision_detection::World::DESTROY, it->second); it = diff1b.getChanges().find("objB1"); EXPECT_NE(diff1b.end(), it); EXPECT_EQ(collision_detection::World::CREATE | collision_detection::World::ADD_SHAPE, it->second); it = diff1b.getChanges().find("objB2"); EXPECT_NE(diff1b.end(), it); EXPECT_EQ(collision_detection::World::CREATE | collision_detection::World::ADD_SHAPE, it->second); it = diff1b.getChanges().find("objB3"); EXPECT_NE(diff1b.end(), it); EXPECT_EQ(collision_detection::World::CREATE | collision_detection::World::ADD_SHAPE, it->second); world1->addToObject("objC", box, Eigen::Affine3d::Identity()); EXPECT_EQ(6, diff1.getChanges().size()); EXPECT_EQ(6, diff1b.getChanges().size()); EXPECT_EQ(3, diff2.getChanges().size()); world2->addToObject("objC", box, Eigen::Affine3d::Identity()); EXPECT_EQ(7, diff1.getChanges().size()); EXPECT_EQ(7, diff1b.getChanges().size()); EXPECT_EQ(4, diff2.getChanges().size()); diff2.setWorld(world1); EXPECT_EQ(7, diff1.getChanges().size()); EXPECT_EQ(7, diff1b.getChanges().size()); EXPECT_EQ(7, diff2.getChanges().size()); it = diff2.getChanges().find("objC"); EXPECT_NE(diff2.end(), it); EXPECT_EQ(collision_detection::World::CREATE | collision_detection::World::ADD_SHAPE | collision_detection::World::DESTROY, it->second); world1->addToObject("objD", box, Eigen::Affine3d::Identity()); EXPECT_EQ(7, diff1.getChanges().size()); EXPECT_EQ(7, diff1b.getChanges().size()); EXPECT_EQ(8, diff2.getChanges().size()); world2->addToObject("objE", box, Eigen::Affine3d::Identity()); EXPECT_EQ(8, diff1.getChanges().size()); EXPECT_EQ(8, diff1b.getChanges().size()); EXPECT_EQ(8, diff2.getChanges().size()); }