void BuildingDlg3d::OnOK( wxCommandEvent &event ) { BuildingDlg::OnOK(event); vtTerrain *pTerr = vtGetTS()->GetCurrentTerrain(); pTerr->GetStructureLayer()->ConstructStructure(m_pBuilding3d); }
void vtRoute::_StringWires(long ll, vtHeightField3d *pHeightField) { // pick pole numbers i and i-1 and string a wire between them long numiterations = NUM_WIRE_SEGMENTS; FPoint3 fp0, fp1; vtUtilNode *n0 = m_Nodes[ll-1]; vtUtilNode *n1 = m_Nodes[ll]; vtUtilStruct *st0 = n0->m_struct; vtUtilStruct *st1 = n1->m_struct; // safety check if (!st0 || !st1) return; DPoint2 p0 = n0->m_Point; DPoint2 p1 = n1->m_Point; pHeightField->ConvertEarthToSurfacePoint(p0, fp0); pHeightField->ConvertEarthToSurfacePoint(p1, fp1); FMatrix4 rot; rot.Identity(); FPoint3 axisY(0, 1, 0); FPoint3 offset, wire0, wire1; vtMesh *pWireMesh; for (int j = 0; j < st1->m_iNumWires; j++) { pWireMesh = new vtMesh(osg::PrimitiveSet::LINE_STRIP, 0, numiterations+1); offset = st0->m_fpWireAtt1[j]; rot.AxisAngle(axisY, n0->dRadAzimuth); rot.Transform(offset, wire0); FPoint3 wire_start = fp0 + wire0; pWireMesh->AddVertex(wire_start); offset = st1->m_fpWireAtt2[j]; rot.AxisAngle(axisY, n1->dRadAzimuth); rot.Transform(offset, wire1); FPoint3 wire_end = fp1 + wire1; _DrawCat(wire_start, wire_end, vtGetTS()->m_fCatenaryFactor, numiterations, pWireMesh); pWireMesh->AddVertex(wire_end); pWireMesh->AddStrip2(numiterations+1, 0); m_pWireGeom->AddMesh(pWireMesh, m_mi_wire); } }
void vtRoute::AddPoint(const DPoint2 &epos, const char *structname) { vtUtilNode *node = new vtUtilNode; node->m_Point = epos; node->m_sStructName = structname; m_Nodes.Append(node); Dirty(); // Load structure for the indicated node. // sPath identifies the path to the Route data vtUtilStruct *struc = vtGetTS()->LoadUtilStructure(node->m_sStructName); if (struc) node->m_struct = struc; }
// // Called when the GUI needs to be informed of a new terrain // void EnviroFrame::SetTerrainToGUI(vtTerrain *pTerrain) { // Some dialogs need to be informed of the current terrain (even if it is NULL) m_pCameraDlg->SetTerrain(pTerrain); m_pEphemDlg->SetTerrain(pTerrain); m_pScenarioSelectDialog->SetTerrain(pTerrain); m_pLayerDlg->SetTerrain(pTerrain); m_pLODDlg->SetTerrain(pTerrain); if (pTerrain) { m_pLocationDlg->SetLocSaver(pTerrain->GetLocSaver()); m_pLocationDlg->SetAnimContainer(pTerrain->GetAnimContainer()); m_pInstanceDlg->SetProjection(pTerrain->GetProjection()); m_pDistanceDlg->SetProjection(pTerrain->GetProjection()); // Fill instance dialog with global and terrain-specific content m_pInstanceDlg->ClearContent(); m_pInstanceDlg->AddContent(&vtGetContent()); if (pTerrain->m_Content.NumItems() != 0) m_pInstanceDlg->AddContent(&pTerrain->m_Content); // Also switch the time dialog to the time engine of the terrain, // not the globe. SetTimeEngine(vtGetTS()->GetTimeEngine()); // If there is paging involved, Inform the LOD dialog vtTiledGeom *geom = pTerrain->GetTiledGeom(); if (geom && m_pLODDlg) m_pLODDlg->SetPagingRange(geom->prange_min, geom->prange_max); bool bAllowRoll = pTerrain->GetParams().GetValueBool(STR_ALLOW_ROLL); m_canvas->SetSpaceNavAllowRoll(bAllowRoll); } else { vtProjection geo; OGRErr err = geo.SetGeogCSFromDatum(EPSG_DATUM_WGS84); if (err == OGRERR_NONE) m_pDistanceDlg->SetProjection(geo); } // Update Title SetTitle(wxGetApp().MakeFrameTitle(pTerrain)); }
void BuildingDlg3d::Modified() { // When a building is modified, we must reconstruct its 3D geometry vtTerrain *pTerr = vtGetTS()->GetCurrentTerrain(); vtStructureLayer *slay = pTerr->GetStructureLayer(); slay->ConstructStructure(m_pBuilding3d); // We might also have to rebuild any linear structures around or on it const DLine2 &foot = m_pBuilding3d->GetOuterFootprint(0); for (uint i = 0; i < slay->size(); i++) { vtFence3d *fen = slay->GetFence(i); if (fen) { bool bInside = false; const DLine2 &pts = fen->GetFencePoints(); for (uint j = 0; j < pts.GetSize(); j++) if (foot.ContainsPoint(pts[j])) bInside = true; if (bInside) slay->ConstructStructure(fen); } } }
void EnviroFrame::OnChar(wxKeyEvent& event) { static NavType prev = NT_Normal; vtTerrain *pTerr = g_App.GetCurrentTerrain(); long key = event.GetKeyCode(); // Keyboard shortcuts ("accelerators") switch (key) { case 27: // Esc: cancel a building or linear we're making if (g_App.m_mode == MM_BUILDINGS && g_App.IsMakingElastic()) g_App.CancelElastic(); else if (g_App.m_mode == MM_LINEARS && g_App.IsMakingElastic()) g_App.CancelElastic(); else // or exit the application { // It's not safe to close immediately, as that will kill the canvas, // and it might some Canvas event that caused us to close. So, // simply stop rendering, and delay closing until the next Idle event. m_canvas->m_bRunning = false; m_bCloseOnIdle = true; } break; case ' ': if (g_App.m_state == AS_Terrain) ToggleNavigate(); break; case 'f': ChangeFlightSpeed(1.8f); break; case 's': ChangeFlightSpeed(1.0f / 1.8f); break; case 'a': g_App.SetMaintain(!g_App.GetMaintain()); break; case '+': SetTerrainDetail(GetTerrainDetail()+1000); break; case '-': SetTerrainDetail(GetTerrainDetail()-1000); break; case 'd': // Toggle grab-pivot if (g_App.m_nav == NT_Grab) g_App.SetNavType(prev); else { prev = g_App.m_nav; g_App.SetNavType(NT_Grab); } break; case 'w': m_bAlwaysMove = !m_bAlwaysMove; if (g_App.m_pTFlyer != NULL) g_App.m_pTFlyer->SetAlwaysMove(m_bAlwaysMove); break; case '[': { float exag = pTerr->GetVerticalExag(); exag /= 1.01; pTerr->SetVerticalExag(exag); } break; case ']': { float exag = pTerr->GetVerticalExag(); exag *= 1.01; pTerr->SetVerticalExag(exag); } break; case 'e': m_bEarthLines = !m_bEarthLines; g_App.ShowEarthLines(m_bEarthLines); break; case 'y': // Example code: modify the terrain by using the (slow) approach of using // vtTerrain methods GetInitialGrid and UpdateElevation. { vtTerrain *pTerr = g_App.GetCurrentTerrain(); if (pTerr && pTerr->GetParams().GetValueBool(STR_ALLOW_GRID_SCULPTING)) { vtElevationGrid *grid = pTerr->GetInitialGrid(); if (grid) { clock_t t1 = clock(); // Raise an area of the terrain int cols, rows; grid->GetDimensions(cols, rows); for (int i = cols / 4; i < cols / 2; i++) for (int j = rows / 4; j < rows / 2; j++) { grid->SetFValue(i, j, grid->GetFValue(i, j) + 40); } pTerr->UpdateElevation(); clock_t t2 = clock(); VTLOG(" Modify1: %.3f sec\n", (float)(t2-t1)/CLOCKS_PER_SEC); // Update the shading and culture pTerr->ReshadeTexture(vtGetTS()->GetSunLightTransform()); DRECT area; area.SetToZero(); pTerr->RedrapeCulture(area); } } } break; case 'Y': // Example code: modify the terrain by using the (fast) approach of using // vtDynTerrainGeom::SetElevation. { vtTerrain *pTerr = g_App.GetCurrentTerrain(); if (pTerr) { vtDynTerrainGeom *dyn = pTerr->GetDynTerrain(); if (dyn) { clock_t t1 = clock(); // Raise an area of the terrain int cols, rows; dyn->GetDimensions(cols, rows); for (int i = cols / 4; i < cols / 2; i++) for (int j = rows / 4; j < rows / 2; j++) { dyn->SetElevation(i, j, dyn->GetElevation(i, j) + 40); } clock_t t2 = clock(); VTLOG(" Modify2: %.3f sec\n", (float)(t2-t1)/CLOCKS_PER_SEC); // Update the shading and culture pTerr->ReshadeTexture(vtGetTS()->GetSunLightTransform()); DRECT area; area.SetToZero(); pTerr->RedrapeCulture(area); } } } break; case 'u': // Example code: modify a small area of terrain around the mouse pointer. { vtTerrain *pTerr = g_App.GetCurrentTerrain(); if (pTerr) { vtDynTerrainGeom *dyn = pTerr->GetDynTerrain(); if (dyn) { // Get 3D cursor location in grid coordinates FPoint3 fpos; g_App.m_pTerrainPicker->GetCurrentPoint(fpos); IPoint2 ipos; dyn->WorldToGrid(fpos, ipos); for (int x = -4; x < 4; x++) for (int y = -4; y < 4; y++) { float val = dyn->GetElevation(ipos.x + x, ipos.y + y); dyn->SetElevation(ipos.x + x, ipos.y + y, val + 40); } // Update the (entire) shading and culture pTerr->ReshadeTexture(vtGetTS()->GetSunLightTransform()); DRECT area; area.SetToZero(); pTerr->RedrapeCulture(area); } } } break; case 'D': // Shift-D // dump camera info g_App.DumpCameraInfo(); break; case 2: // Ctrl-B // toggle demo g_App.ToggleDemo(); break; case WXK_F11: DoTestCode(); break; case WXK_F12: m_pSceneGraphDlg->Show(true); break; case WXK_DELETE: DeleteAllSelected(); break; default: event.Skip(); break; } }
void EnviroFrame::CarveTerrainToFitNode(osg::Node *node) { vtTerrain *terr = g_App.GetCurrentTerrain(); if (!terr) return; vtDynTerrainGeom *dyn = terr->GetDynTerrain(); if (!dyn) return; FSphere sph; GetBoundSphere(node, sph, true); int changed = 0; int cols, rows; dyn->GetDimensions(cols, rows); const FPoint3 yvec(0,100,0); for (int c = 0; c < cols; c++) { for (int r = 0; r < rows; r++) { FPoint3 wpos; dyn->GetWorldLocation(c, r, wpos); if (wpos.x < (sph.center.x - sph.radius)) continue; if (wpos.x > (sph.center.x + sph.radius)) continue; if (wpos.z < (sph.center.z - sph.radius)) continue; if (wpos.z > (sph.center.z + sph.radius)) continue; // Shoot a ray upwards through the terrain surface point vtHitList HitList; int iNumHits = vtIntersect(node, wpos - yvec, wpos + yvec, HitList); if (iNumHits) { FPoint3 pos = HitList.front().point; dyn->SetElevation(c, r, pos.y); changed++; } } } if (changed != 0) { wxString msg; msg.Printf(_T("Adjusted %d heixels. Re-shade the terrain?"), changed); int res = wxMessageBox(msg, _T(""), wxYES_NO, this); if (res == wxYES) { // Update the (entire) shading and culture EnableContinuousRendering(false); OpenProgressDialog(_("Recalculating Shading"), _T(""), false, this); terr->ReshadeTexture(vtGetTS()->GetSunLightTransform(), progress_callback); DRECT area; area.SetToZero(); terr->RedrapeCulture(area); CloseProgressDialog(); EnableContinuousRendering(true); } } }
float CVisualImpactCalculatorOSG::Implementation(bool bOneOffMode, GDALRasterBand *pRasterBand, float fScaleFactor, double dXSampleInterval, double dYSampleInterval, bool progress_callback(int)) { if (!m_bInitialised) return 0.0; osgViewer::Viewer *pViewer = vtGetScene()->getViewer(); osgViewer::Viewer::Cameras ActiveCameras; std::vector<CameraMask> NodeMasks; pViewer->getCameras(ActiveCameras, true); // Stop any other cameras rendering the scene for (osgViewer::Viewer::Cameras::iterator itr = ActiveCameras.begin(); itr != ActiveCameras.end(); ++itr) { if (*itr != m_pVisualImpactCamera.get()) { NodeMasks.push_back(CameraMask(*itr, (*itr)->getNodeMask())); (*itr)->setNodeMask(0); } } // Set up the render bins for (VisualImpactContributors::iterator itr = m_VisualImpactContributors.begin(); itr != m_VisualImpactContributors.end(); itr++) (*itr)->getOrCreateStateSet()->setRenderBinDetails(VISUAL_IMPACT_BIN_NUMBER, VISUAL_IMPACT_BIN_NAME); // Pick up the current main scene camera state osg::StateSet* pStateSet = new osg::StateSet(*ActiveCameras[0]->getOrCreateStateSet(), osg::CopyOp::DEEP_COPY_ALL); pStateSet->setAttribute(m_pVisualImpactCamera->getViewport()); m_pVisualImpactCamera->setStateSet(pStateSet); m_pVisualImpactCamera->setClearColor(ActiveCameras[0]->getClearColor()); // Enable the visual impact camera m_pVisualImpactCamera->setNodeMask(0xffffffff); if (bOneOffMode) { m_pVisualImpactCamera->setViewMatrix(m_ViewMatrix); pViewer->frame(); // Disable the visual impact camera m_pVisualImpactCamera->setNodeMask(0); for(std::vector<CameraMask>::iterator itr = NodeMasks.begin(); itr != NodeMasks.end(); ++itr) itr->m_pCamera->setNodeMask(itr->m_NodeMask); for (VisualImpactContributors::iterator itr = m_VisualImpactContributors.begin(); itr != m_VisualImpactContributors.end(); itr++) { osg::StateSet *pStateSet = (*itr)->getOrCreateStateSet(); pStateSet->setRenderBinMode(osg::StateSet::INHERIT_RENDERBIN_DETAILS); pStateSet->setRenderingHint(osg::StateSet::DEFAULT_BIN); } return InnerImplementation(); } else { DPoint2 CameraOrigin; DPoint2 CurrentCamera; vtHeightField3d *pHeightField = vtGetTS()->GetCurrentTerrain()->GetHeightField(); DRECT EarthExtents = pHeightField->GetEarthExtents(); CameraOrigin.x = EarthExtents.left; CameraOrigin.y = EarthExtents.bottom; int iCurrentY = 0; int iXsize = (int)((EarthExtents.right - EarthExtents.left)/dXSampleInterval); int iYsize = (int)((EarthExtents.top - EarthExtents.bottom)/dYSampleInterval); int iTotalProgress = iXsize * iYsize; #ifdef _DEBUG int iBlockSizeX, iBlockSizeY; pRasterBand->GetBlockSize(&iBlockSizeX, &iBlockSizeY); #endif for (CurrentCamera.y = CameraOrigin.y; CurrentCamera.y < EarthExtents.top; CurrentCamera.y += dYSampleInterval) { // Process horizontal scanline int iCurrentX = 0; for (CurrentCamera.x = CameraOrigin.x; CurrentCamera.x < EarthExtents.right; CurrentCamera.x += dXSampleInterval) { FPoint3 CameraTranslate; pHeightField->ConvertEarthToSurfacePoint(CurrentCamera, CameraTranslate); m_pVisualImpactCamera->setViewMatrixAsLookAt(v2s(CameraTranslate), v2s(m_Target), osg::Vec3(0.0, 1.0, 0.0)); pViewer->frame(); float fFactor = InnerImplementation(); pRasterBand->RasterIO(GF_Write, iCurrentX, iYsize - iCurrentY - 1, 1, 1, &fFactor, 1, 1, GDT_Float32, 0, 0); iCurrentX++; if ((*progress_callback)(100 * (iCurrentY * iXsize + iCurrentX) / iTotalProgress)) { // Disable the visual impact camera m_pVisualImpactCamera->setNodeMask(0); for(std::vector<CameraMask>::iterator itr = NodeMasks.begin(); itr != NodeMasks.end(); ++itr) itr->m_pCamera->setNodeMask(itr->m_NodeMask); for (VisualImpactContributors::iterator itr = m_VisualImpactContributors.begin(); itr != m_VisualImpactContributors.end(); itr++) { osg::StateSet *pStateSet = (*itr)->getOrCreateStateSet(); pStateSet->setRenderBinMode(osg::StateSet::INHERIT_RENDERBIN_DETAILS); pStateSet->setRenderingHint(osg::StateSet::DEFAULT_BIN); } VTLOG("CVisualImpactCalculatorOSG::Implementation - Cancelled by user\n"); return -1.0f; } } iCurrentY++; } // Disable the visual impact camera m_pVisualImpactCamera->setNodeMask(0); for(std::vector<CameraMask>::iterator itr = NodeMasks.begin(); itr != NodeMasks.end(); ++itr) itr->m_pCamera->setNodeMask(itr->m_NodeMask); for (VisualImpactContributors::iterator itr = m_VisualImpactContributors.begin(); itr != m_VisualImpactContributors.end(); itr++) { osg::StateSet *pStateSet = (*itr)->getOrCreateStateSet(); pStateSet->setRenderBinMode(osg::StateSet::INHERIT_RENDERBIN_DETAILS); pStateSet->setRenderingHint(osg::StateSet::DEFAULT_BIN); } return 0.0f; } }
void BuildingDlg3d::Setup(vtBuilding3d *bld3d) { vtTerrain *pTerr = vtGetTS()->GetCurrentTerrain(); m_pBuilding3d = bld3d; BuildingDlg::Setup(pTerr->GetStructureLayer(), bld3d); }