void DataRenderer::loadComplexModel(const uint32_t &id, opendlv::data::situation::ComplexModel &cm) { std::shared_ptr<istream> in = m_scnxArchive->getModelData(cm.getModelFile()); if (in.get()) { // Load model. OBJXArchive *objxArchive = NULL; if (cm.getModelFile().find(".objx") != string::npos) { objxArchive = OBJXArchiveFactory::getInstance().getOBJXArchive(*in); } else if (cm.getModelFile().find(".obj") != string::npos) { objxArchive = OBJXArchiveFactory::getInstance().getOBJXArchiveFromPlainOBJFile(*in); } if (objxArchive != NULL) { m_listOfLoadedOBJXArchives.push_back(objxArchive); vector<TriangleSet> listOfTriangleSets = objxArchive->getListOfTriangleSets(); if (listOfTriangleSets.size() > 0) { clog << "OBJ model successfully opened (containing " << listOfTriangleSets.size() << " sets of triangles)." << endl; clog << " Translation: " << cm.getPosition().toString() << endl; clog << " Rotation: " << cm.getRotation().toString() << endl; m_mapOfModels[id] = listOfTriangleSets; } else { clog << "OBJ model could not be opened." << endl; } } } }
void ScenarioRenderer::loadGroundBasedComplexModel(ComplexModel &cm) { SharedPointer<istream> in = m_scnxArchive->getModelData(cm.getModelFile()); if (in.isValid()) { // Load model. OBJXArchive *objxArchive = NULL; if (cm.getModelFile().find(".objx") != string::npos) { objxArchive = OBJXArchiveFactory::getInstance().getOBJXArchive(*in); } else if (cm.getModelFile().find(".obj") != string::npos) { objxArchive = OBJXArchiveFactory::getInstance().getOBJXArchiveFromPlainOBJFile(*in); } if (objxArchive != NULL) { m_listOfLoadedOBJXArchives.push_back(objxArchive); vector<TriangleSet> listOfTriangleSets = objxArchive->getListOfTriangleSets(); if (listOfTriangleSets.size() > 0) { clog << "OBJ model successfully opened (containing " << listOfTriangleSets.size() << " sets of triangles)." << endl; clog << " Translation: " << cm.getPosition().toString() << endl; clog << " Rotation: " << cm.getRotation().toString() << endl; m_mapOfGroundBasedComplexModels[cm.toString()] = listOfTriangleSets; } else { clog << "OBJ model could not be opened." << endl; } } } }
TransformGroup* GroundBasedComplexModelLoader::getGroundBasedComplexModels(const SCNXArchive &scnxArchive) const { TransformGroup *complexModels = new TransformGroup(); // Get list of all ground based complex models. vector<ComplexModel*> listOfComplexModels = scnxArchive.getListOfGroundBasedComplexModels(); // Iterate over all ground based complex models and try to build a transform group. vector<ComplexModel*>::iterator jt = listOfComplexModels.begin(); while (jt != listOfComplexModels.end()) { ComplexModel *cm = (*jt++); SharedPointer<istream> in = scnxArchive.getModelData(cm->getModelFile()); if (in.isValid()) { Node *model = NULL; // Check model. OBJXArchive *objxArchive = NULL; if (cm->getModelFile().find(".objx") != string::npos) { objxArchive = OBJXArchiveFactory::getInstance().getOBJXArchive(*in); } else if (cm->getModelFile().find(".obj") != string::npos) { objxArchive = OBJXArchiveFactory::getInstance().getOBJXArchiveFromPlainOBJFile(*in); } if (objxArchive != NULL) { model = objxArchive->createTransformGroup(NodeDescriptor(cm->getName())); if (model != NULL) { clog << "OBJ model successfully opened." << endl; clog << " Translation: " << cm->getPosition().toString() << endl; clog << " Rotation: " << cm->getRotation().toString() << endl; TransformGroup *complexModel = new TransformGroup(); // Translation. Point3 translation(cm->getPosition()); complexModel->setTranslation(translation); // TODO: Achsenprüfung!! Point3 rotation(cm->getRotation().getX(), cm->getRotation().getZ(), cm->getRotation().getY()); complexModel->setRotation(rotation); complexModel->addChild(model); complexModels->addChild(complexModel); } else { clog << "OBJ model could not be opened." << endl; } OPENDAVINCI_CORE_DELETE_POINTER(objxArchive); } } } return complexModels; }
OpenGLGrabber::OpenGLGrabber(const KeyValueConfiguration &kvc, const ImageGrabberID &imageGrabberID, const ImageGrabberCalibration &imageGrabberCalibration, hesperia::data::environment::EgoState &egoState, core::base::FIFOQueue &obstacles) : ImageGrabber(imageGrabberID, imageGrabberCalibration), m_render(OpenGLGrabber::IN_CAR), m_kvc(kvc), m_image(), m_sharedMemory(), m_root(), m_car(), m_sensors(), m_mapOfObstacles(), m_egoState(egoState), m_FIFO_Obstacles(obstacles) { const URL urlOfSCNXFile(m_kvc.getValue<string>("global.scenario")); const bool SHOW_GRID = (m_kvc.getValue<uint8_t>("global.showgrid") == 1); if (urlOfSCNXFile.isValid()) { m_root = core::SharedPointer<TransformGroup>(new hesperia::threeD::TransformGroup()); m_car = core::SharedPointer<TransformGroup>(new hesperia::threeD::TransformGroup()); m_sensors = core::SharedPointer<TransformGroup>(new hesperia::threeD::TransformGroup()); SCNXArchive &scnxArchive = SCNXArchiveFactory::getInstance().getSCNXArchive(urlOfSCNXFile); // Read scnxArchive and decorate it for getting displayed in an OpenGL scene. const bool SHOW_LANE_CONNECTORS = false; m_root->addChild(DecoratorFactory::getInstance().decorate(scnxArchive, SHOW_LANE_CONNECTORS)); if (SHOW_GRID) { m_root->addChild(new XYZAxes(NodeDescriptor("XYZAxes"))); m_root->addChild(new Grid(NodeDescriptor("Grid"), 10, 2)); } string objxModel(m_kvc.getValue<string>("global.car")); cout << "Opening file stream to car model " << objxModel << endl; fstream fin(objxModel.c_str(), ios::in | ios::binary); if (fin.good()) { cout << "Loading car model" << endl; OBJXArchive *objxArchive = OBJXArchiveFactory::getInstance().getOBJXArchive(fin); fin.close(); if (objxArchive != NULL) { // Decorate objxArchive for getting displayed in an OpenGL scene. m_car->addChild(objxArchive->createTransformGroup(NodeDescriptor("Car"))); } } m_sharedMemory = core::wrapper::SharedMemoryFactory::createSharedMemory("ChaseCar", 640 * 480 * 3); m_image = core::SharedPointer<core::wrapper::Image>(core::wrapper::ImageFactory::getInstance().getImage(640, 480, core::wrapper::Image::BGR_24BIT, static_cast<char*>(m_sharedMemory->getSharedMemory()))); if (m_image.isValid()) { cerr << "OpenGLGrabber initialized." << endl; } } }
void DataRenderer::setEgoStateModel(const string &fn) { Lock l(m_dataRendererMutex); cout << "Trying to load file stream to car model " << fn << endl; fstream fin(fn.c_str(), ios::in | ios::binary); OBJXArchive *objxArchive = OBJXArchiveFactory::getInstance().getOBJXArchive(fin); if (objxArchive != NULL) { m_egoStateModel = objxArchive->getListOfTriangleSets(); if (m_egoStateModel.size() > 0) { clog << "OBJ model successfully opened (containing " << m_egoStateModel.size() << " sets of triangles)." << endl; } else { clog << "OBJ model could not be opened." << endl; } m_listOfLoadedOBJXArchives.push_back(objxArchive); } }
OBJXArchive* OBJXArchiveFactory::getOBJXArchiveFromPlainOBJFile(istream &in) throw (InvalidArgumentException) { if (!(in.good())) { // Try to rewind the stream. clog << "Trying to rewind the stream." << endl; in.clear(); in.seekg(ios::beg); if (!(in.good())) { HESPERIA_CORE_THROW_EXCEPTION(InvalidArgumentException, "Given inputstream is invalid."); } } OBJXArchive *objxArchive = new OBJXArchive(); char c; stringstream s; while (in.good()) { in.get(c); s << c; } objxArchive->setContentsOfObjFile(s.str()); return objxArchive; }
OBJXArchive* OBJXArchiveFactory::getOBJXArchive(istream &in) throw (InvalidArgumentException) { if (!(in.good())) { // Try to rewind the stream. clog << "Trying to rewind the stream." << endl; in.clear(); in.seekg(ios::beg); if (!(in.good())) { HESPERIA_CORE_THROW_EXCEPTION(InvalidArgumentException, "Given inputstream is invalid."); } } OBJXArchive *objxArchive = NULL; // Use CompressionFactory to read the contents of the OBJXArchive. core::wrapper::DecompressedData *data = core::wrapper::CompressionFactory::getInstance().getContents(in); if (data != NULL) { // Create OBJXArchive. objxArchive = new OBJXArchive(); vector<string> listOfEntries = data->getListOfEntries(); vector<string>::iterator it = listOfEntries.begin(); while (it != listOfEntries.end()) { string entry = (*it++); if (entry.find(".obj") != string::npos) { // Set object file. istream *stream = data->getInputStreamFor(entry); char c; stringstream s; while (stream->good()) { stream->get(c); s << c; } objxArchive->setContentsOfObjFile(s.str()); } else if (entry.find(".mtl") != string::npos) { // Set material file. istream *stream = data->getInputStreamFor(entry); char c; stringstream s; while (stream->good()) { stream->get(c); s << c; } objxArchive->setContentsOfMtlFile(s.str()); } else { // Try to load an image. istream *stream = data->getInputStreamFor(entry); if (stream != NULL) { core::wrapper::Image *image = core::wrapper::ImageFactory::getInstance().getImage(*stream); if (image != NULL) { // TODO: Check where origin lies. image->rotate(static_cast<float>(data::Constants::PI)); // Remove any directory prefixes from the entry. string name = entry; if (name.rfind('/') != string::npos) { name = name.substr(name.rfind('/') + 1); } objxArchive->addImage(name, image); } } } } } return objxArchive; }
void EnvironmentViewerGLWidget::createSceneGraph() { m_root = new TransformGroup(); m_stationaryElements = new TransformGroup(); m_dynamicElements = new TransformGroup(); m_measurements = new TransformGroup(); m_root->addChild(m_stationaryElements); m_root->addChild(m_dynamicElements); m_root->addChild(m_measurements); /*******************************************************************/ /* Stationary elements. */ /*******************************************************************/ m_stationaryElements->addChild(new hesperia::threeD::models::XYZAxes(NodeDescriptor("XYZAxes"), 1, 10)); m_stationaryElements->addChild(new hesperia::threeD::models::Grid(NodeDescriptor("Grid"), 10, 1)); // Setup surroundings. const URL urlOfSCNXFile(getPlugIn().getKeyValueConfiguration().getValue<string>("global.scenario")); if (urlOfSCNXFile.isValid()) { SCNXArchive &scnxArchive = SCNXArchiveFactory::getInstance().getSCNXArchive(urlOfSCNXFile); // Read scnxArchive and decorate it for getting displayed in an OpenGL scene. Node *surroundings = DecoratorFactory::getInstance().decorate(scnxArchive); if (surroundings != NULL) { surroundings->setNodeDescriptor(NodeDescriptor("Surroundings")); m_stationaryElements->addChild(surroundings); } } /*******************************************************************/ /* Dynamic elements. */ /*******************************************************************/ string objxModel(getPlugIn().getKeyValueConfiguration().getValue<string>("global.car")); cout << "Opening file stream to car model " << objxModel << endl; fstream fin(objxModel.c_str(), ios::in | ios::binary); if (fin.good()) { cout << "Loading car model" << endl; OBJXArchive *objxArchive = OBJXArchiveFactory::getInstance().getOBJXArchive(fin); fin.close(); if (objxArchive != NULL) { // Decorate objxArchive for getting displayed in an OpenGL scene. m_egoStateNodeDescriptor = NodeDescriptor("EgoCar"); m_listOfCameraAssignableNodes.push_back(m_egoStateNodeDescriptor); m_egoStateNode = objxArchive->createTransformGroup(m_egoStateNodeDescriptor); } if (m_egoStateNode == NULL) { OPENDAVINCI_CORE_THROW_EXCEPTION(InvalidArgumentException, "Could not load car model"); } else { m_dynamicElements->addChild(m_egoStateNode); // EgoCar is traceable. NodeDescriptor traceableNodeDescriptor = NodeDescriptor("EgoCar (Trace)"); TransformGroup *traceableNode = new TransformGroup(traceableNodeDescriptor); m_mapOfTraceablePositions[traceableNodeDescriptor] = traceableNode; m_dynamicElements->addChild(traceableNode); } } m_plannedRoute = new TransformGroup(NodeDescriptor("Planned Route")); m_dynamicElements->addChild(m_plannedRoute); m_lines = new TransformGroup(NodeDescriptor("Individual Lines")); m_dynamicElements->addChild(m_lines); /*******************************************************************/ /* Measurements. */ /*******************************************************************/ // Create node for showing contoured objects. m_contouredObjectsNode = new TransformGroup(NodeDescriptor("Contoured Objects")); m_measurements->addChild(m_contouredObjectsNode); m_obstaclesRoot = new TransformGroup(NodeDescriptor("Obstacles")); m_measurements->addChild(m_obstaclesRoot); }