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; }
void OBJXGLWidget::initScene() { Lock l(m_modelMutex); // Initialize. m_model = new TransformGroup(); TransformGroup *tg = new TransformGroup(); // Add model to be shown. tg->addChild(m_model); tg->addChild(new XYZAxes(NodeDescriptor("XYZAxes"), 1, 12)); tg->addChild(new Grid(NodeDescriptor("Grid"), 10, 1)); m_root = tg; }
Node* DecoratorFactory::decorate(scenario::SCNXArchive &scnxArchive, const bool &showLaneConnectors) { TransformGroup *tg = new TransformGroup(); Scenario &scenario = scnxArchive.getScenario(); if (scnxArchive.getAerialImage() != NULL) { clog << "AerialImage loaded." << endl; Point3 origin(scenario.getGround().getAerialImage().getOriginX(), scenario.getGround().getAerialImage().getOriginY(), 0); Point3 scaling(scenario.getGround().getAerialImage().getMeterPerPixelX(), scenario.getGround().getAerialImage().getMeterPerPixelY(), 0); AerialImage *ai = new AerialImage( NodeDescriptor("AerialImage"), scnxArchive.getAerialImage(), origin, scaling, static_cast<float> (scenario.getGround().getAerialImage().getRotationZ())); tg->addChild(ai); } if (scnxArchive.getHeightImage() != NULL) { clog << "HeightImage available but will be skipped." << endl; /* Point3 origin(scenario.getGround().getHeightImage().getOriginX(), scenario.getGround().getHeightImage().getOriginY(), 0); Point3 scaling(scenario.getGround().getHeightImage().getMeterPerPixelX(), scenario.getGround().getHeightImage().getMeterPerPixelY(), 0); HeightGrid *hg = new HeightGrid(NodeDescriptor("HeightGrid"), scnxArchive.getHeightImage(), origin, scaling, static_cast<float>(scenario.getGround().getHeightImage().getRotationZ()), static_cast<float>(scenario.getGround().getHeightImage().getGroundHeight()), static_cast<float>(scenario.getGround().getHeightImage().getMinimumHeight()), static_cast<float>(scenario.getGround().getHeightImage().getMaximumHeight())); tg->addChild(hg); */ } ScenarioOpenGLSceneTransformation scnOpenGL(showLaneConnectors); scenario.accept(scnOpenGL); tg->addChild(scnOpenGL.getRoot()); // Load complex models. GroundBasedComplexModelLoader gbcml; TransformGroup *complexModels = gbcml.getGroundBasedComplexModels(scnxArchive); if (complexModels != NULL) { tg->addChild(complexModels); } return tg; }
core::SharedPointer<core::wrapper::Image> OpenGLGrabber::getNextImage() { if ( (m_sharedMemory.isValid()) && (m_sharedMemory->isValid()) ) { m_sharedMemory->lock(); // Render the image right before grabbing it. switch (m_render) { case OpenGLGrabber::IN_CAR: renderNextImageInCar(); m_FIFO_Obstacles.clear(); break; case OpenGLGrabber::CHASE_CAR: renderNextImageChaseCar(); m_FIFO_Obstacles.clear(); break; case OpenGLGrabber::CHASE_CAR_SENSORS: { const uint32_t size = m_FIFO_Obstacles.getSize(); for(uint32_t i = 0; i < size; i++) { Container c = m_FIFO_Obstacles.leave(); if (c.getDataType() == Container::OBSTACLE) { Obstacle obstacle = c.getData<Obstacle>(); // Check if sensor FOV-"Obstacle": if (obstacle.getID() >= 9000) { switch (obstacle.getState()) { case Obstacle::REMOVE: { // Remove obstacle. map<uint32_t, Node*>::iterator result = m_mapOfObstacles.find(obstacle.getID()); if (result != m_mapOfObstacles.end()) { // Remove child from scene graph node. m_sensors->removeChild(result->second); // Remove entry from map. m_mapOfObstacles.erase(result); } } break; case Obstacle::UPDATE: { map<uint32_t, Node*>::iterator result = m_mapOfObstacles.find(obstacle.getID()); if (result != m_mapOfObstacles.end()) { // Remove child from scene graph node. m_sensors->removeChild(result->second); // Remove entry from map. m_mapOfObstacles.erase(result); } // Update obstacle. TransformGroup *contourTG = new TransformGroup(); vector<Point3> contour = obstacle.getPolygon().getVertices(); // Close polygons. Point3 p = contour.at(0); contour.push_back(p); for (uint32_t k = 0; k < contour.size() - 1; k++) { Point3 A = contour.at(k); A.setZ(0.5); Point3 B = contour.at(k+1); B.setZ(0.5); contourTG->addChild(new hesperia::threeD::models::Line(NodeDescriptor(), A, B, Point3(0, 1, 0), 2)); } m_mapOfObstacles[obstacle.getID()] = contourTG; m_sensors->addChild(contourTG); } break; } } } } renderNextImageChaseCarSensors(); } break; } // TODO Read pixels using BGRA!!! glReadBuffer(GL_BACK); glPixelStorei(GL_PACK_ALIGNMENT, 1); glReadPixels(0, 0, m_image->getWidth(), m_image->getHeight(), GL_BGR, GL_UNSIGNED_BYTE, m_sharedMemory->getSharedMemory()); // Flip the image horizontally. m_image->flipHorizontally(); m_sharedMemory->unlock(); } return m_image; }
void EnvironmentViewerGLWidget::nextContainer(Container &c) { if (c.getDataType() == Container::EGOSTATE) { m_numberOfReceivedEgoStates++; if (m_egoStateNode != NULL) { Lock l(m_rootMutex); EgoState egostate = c.getData<EgoState>(); Point3 dir(0, 0, egostate.getRotation().getAngleXY()); m_egoStateNode->setRotation(dir); m_egoStateNode->setTranslation(egostate.getPosition()); Position egoPosition; egoPosition.setPosition(egostate.getPosition()); egoPosition.setRotation(egostate.getRotation()); m_mapOfCurrentPositions[m_egoStateNodeDescriptor] = egoPosition; if ( (m_numberOfReceivedEgoStates % 30) == 0 ) { NodeDescriptor nd("EgoCar (Trace)"); TransformGroup *tg = m_mapOfTraceablePositions[nd]; if (tg != NULL) { Point3 color(0, 0, 1); hesperia::threeD::models::Point *p = new hesperia::threeD::models::Point(NodeDescriptor("Trace"), egostate.getPosition(), color, 5); tg->addChild(p); } } } } if (c.getDataType() == Container::CONTOUREDOBJECTS) { if (m_contouredObjectsNode != NULL) { Lock l(m_rootMutex); ContouredObjects cos = c.getData<ContouredObjects>(); vector<ContouredObject> listOfContouredObjects = cos.getContouredObjects(); vector<ContouredObject>::iterator it = listOfContouredObjects.begin(); m_contouredObjectsNode->deleteAllChildren(); while (it != listOfContouredObjects.end()) { vector<Point3> contour = (*it).getContour(); vector<Point3>::iterator jt = contour.begin(); while (jt != contour.end()) { m_contouredObjectsNode->addChild(new hesperia::threeD::models::Point(NodeDescriptor("Point"), (*jt), Point3(1, 0, 0), 2)); jt++; } it++; } } } if (c.getDataType() == Container::ROUTE) { if (m_plannedRoute != NULL) { Lock l(m_rootMutex); Route r = c.getData<Route>(); vector<Point3> listOfVertices = r.getListOfPoints(); const uint32_t SIZE = listOfVertices.size(); if (SIZE > 0) { m_plannedRoute->deleteAllChildren(); for (uint32_t i = 0; i < SIZE - 1; i++) { Point3 posA = listOfVertices.at(i); posA.setZ(0.05); Point3 posB = listOfVertices.at(i+1); posB.setZ(0.05); m_plannedRoute->addChild(new hesperia::threeD::models::Line(NodeDescriptor(), posA, posB, Point3(0, 1, 0), 6)); } } } } if (c.getDataType() == Container::DRAW_LINE) { if (m_lines != NULL) { Lock l(m_rootMutex); hesperia::data::environment::Line line = c.getData<Line>(); Point3 posA = line.getA(); posA.setZ(0.05); Point3 posB = line.getB(); posB.setZ(0.05); m_lines->addChild(new hesperia::threeD::models::Line(NodeDescriptor(), posA, posB, Point3(1, 0, 0), 6)); } } if (c.getDataType() == Container::OBSTACLE) { if (m_obstaclesRoot != NULL) { Lock l(m_rootMutex); Obstacle obstacle = c.getData<Obstacle>(); switch (obstacle.getState()) { case Obstacle::REMOVE: { // Remove obstacle. map<uint32_t, Node*>::iterator result = m_mapOfObstacles.find(obstacle.getID()); if (result != m_mapOfObstacles.end()) { // Remove child from scene graph node. m_obstaclesRoot->removeChild(result->second); // Remove entry from map. m_mapOfObstacles.erase(result); } } break; case Obstacle::UPDATE: { map<uint32_t, Node*>::iterator result = m_mapOfObstacles.find(obstacle.getID()); if (result != m_mapOfObstacles.end()) { // Remove child from scene graph node. m_obstaclesRoot->removeChild(result->second); // Remove entry from map. m_mapOfObstacles.erase(result); } // Update obstacle. TransformGroup *contourTG = new TransformGroup(); vector<Point3> contour = obstacle.getPolygon().getVertices(); // Close polygons. Point3 p = contour.at(0); contour.push_back(p); for (uint32_t k = 0; k < contour.size() - 1; k++) { Point3 A = contour.at(k); A.setZ(0.5); Point3 B = contour.at(k+1); B.setZ(0.5); contourTG->addChild(new hesperia::threeD::models::Line(NodeDescriptor(), A, B, Point3(0, 1, 0), 2)); } m_mapOfObstacles[obstacle.getID()] = contourTG; m_obstaclesRoot->addChild(contourTG); } break; } } } }
bool PraetoriansTerrainWater::loadPackedMedia(const char* path) { unsigned int signature; unsigned short chunkid; unsigned int chunklength; unsigned int texturescount;///use one in this version unsigned int watercount; unsigned int vertexcount; unsigned int indexcount; Tuple3f* vertices; unsigned short* indices; Tuple4ub* colors; Tuple2f* txcoords; ArchivedFile* file; WaterDatabase* wdatabase; if (!(file = FileSystem::checkOut(path))) return Logger::writeErrorLog(String("Could not load -> ") + path); wdatabase = Gateway::getWaterDatabase(); file->read(&signature, 4); file->read(&chunkid, 2); file->read(&chunklength, 4); file->read(&texturescount, 4); for (unsigned int i = 0; i < texturescount; i++) file->seek((256 * 256 * 4) + 6, SEEKD); file->read(&watercount, 4); for (unsigned int i = 0; i < watercount; i++) { file->read(&chunkid, 2); file->read(&chunklength, 4); file->seek(48, SEEKD); file->read(&vertexcount, 4); vertices = new Tuple3f[vertexcount]; colors = new Tuple4ub[vertexcount]; txcoords = new Tuple2f[vertexcount]; for (unsigned int j = 0; j < vertexcount; j++) { file->read(vertices[j], 12); Swap(vertices[j].x, vertices[j].z); file->read(colors[j], 4); Swap(colors[j].x, colors[j].z); file->read(txcoords[j], 8); } file->read(&indexcount, 4); indices = new unsigned short[indexcount]; file->read(indices, indexcount * 2); String watername = String("H2O_") + int(wdatabase->getWatersCount()); Geometry* geometry; geometry = new Geometry(watername, indexcount, vertexcount); geometry->setIndices(indices, false); geometry->setVertices(vertices, false); geometry->setColors(colors, false); geometry->setTextureElements(txcoords, 2, false); geometry->computeBounds(); Appearance* appearance = new Appearance(); appearance->setBlendAttributes(BlendAttributes(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); appearance->setTexture(0, wdatabase->getWaterTexture()); Model* model = new Model(); model->setAppearance(appearance); model->setGeometry(geometry); TransformGroup* group = new TransformGroup(); group->addChild(model); group->updateBoundsDescriptor(); wdatabase->addWaterModel(group); deleteArray(vertices); deleteArray(indices); deleteArray(colors); deleteArray(txcoords); } FileSystem::checkIn(file); return true; }