void UtilDlg::OnInitDialog(wxInitDialogEvent& event) { VTLOG("UtilDlg looking for items of type utility pole.\n"); vtContentManager &mng = vtGetContent(); int found = 0; m_pChoice->Clear(); for (uint i = 0; i < mng.NumItems(); i++) { vtString str; vtItem *item = mng.GetItem(i); if (item->GetValueString("type", str)) { if (str == "utility pole") { m_pChoice->Append(wxString::FromAscii(item->m_name)); found++; } } } TransferDataToWindow(); VTLOG("\t%d items, %d found.\n", mng.NumItems(), found); wxString val = m_pChoice->GetStringSelection(); g_App.SetPowerOptions((const char *) val.mb_str(wxConvUTF8)); }
/** * Use the height data in the grid to fill a bitmap with colors. * * \param pBM The bitmap to be colored. * \param cmap The mapping of elevation values to colors. * \param iGranularity The smoothness of the mapping, expressed as the size * of the internal mapping table. 2000 is a generally good value. * \param nodata The color to use for NODATA areas, where there are no elevation values. * \param progress_callback If supplied, this function will be called back * with a value of 0 to 100 as the operation progresses. * * \return true if any invalid elevation values were encountered. */ bool vtHeightFieldGrid3d::ColorDibFromElevation(vtBitmapBase *pBM, ColorMap *cmap, int iGranularity, const RGBAi &nodata, bool progress_callback(int)) const { if (!pBM || !cmap) return false; VTLOG1("ColorDibFromElevation:"); float fMin, fMax; GetHeightExtents(fMin, fMax); float fRange = fMax - fMin; bool bFlat = (fRange < 0.0001f); if (bFlat) { // avoid numeric trouble with flat terrains by growing range fMin -= 1; fMax += 1; fRange = fMax - fMin; } VTLOG(" table of %d values, first [%d %d %d],\n", cmap->Num(), cmap->Color(0).r, cmap->Color(0).g, cmap->Color(0).b); VTLOG("\tmin %g, max %g, range %g, granularity %d\n", fMin, fMax, fRange, iGranularity); // Rather than look through the color map for each pixel, pre-build // a color lookup table once - should be faster in nearly all cases. cmap->GenerateColorTable(iGranularity, fMin, fMax); return ColorDibFromTable(pBM, cmap, nodata, progress_callback); }
void MapServerDlg::OnQueryLayers( wxCommandEvent &event ) { #if SUPPORT_CURL VTLOG1("OnQueryLayers\n"); wxString val = GetBaseUrl()->GetValue(); vtString url = (const char *) val.mb_str(wxConvUTF8); OpenProgressDialog(_("Querying server..."), val, false, this); VTLOG(" from base URL: %s\n", (const char *)url); vtString msg; bool success = GetLayersFromWMS(url, m_pServers->at(m_iServer).m_layers, msg, progress_callback); CloseProgressDialog(); if (success) { UpdateLayerList(); UpdateLayerDescription(); UpdateURL(); } else { VTLOG("Error: '%s'\n", (const char *)msg); wxString str(msg, wxConvUTF8); wxMessageBox(str); } #endif // SUPPORT_CURL }
void LocationDlg::RecallFrom(const char *locname) { if (m_pSaver->RecallFrom(locname)) VTLOG(" Recalled location '%s'\n", (const char *)locname); else VTLOG(" Couldn't recall location '%s'\n", (const char *)locname); }
int vtStructureArray::AddFoundations(vtHeightField *pHF, bool progress_callback(int)) { vtLevel *pLev, *pNewLev; int i, j, pts, built = 0; float fElev; int selected = NumSelected(); int size = GetSize(); VTLOG("AddFoundations: %d selected, %d total, ", selected, size); for (i = 0; i < size; i++) { if (progress_callback != NULL) progress_callback(i * 99 / size); vtStructure *str = GetAt(i); vtBuilding *bld = str->GetBuilding(); if (!bld) continue; if (selected > 0 && !str->IsSelected()) continue; // Get the outer footprint of the lowest level pLev = bld->GetLevel(0); const DLine2 &foot = pLev->GetOuterFootprint(); pts = foot.GetSize(); float fMin = 1E9, fMax = -1E9; for (j = 0; j < pts; j++) { pHF->FindAltitudeOnEarth(foot.GetAt(j), fElev); if (fElev < fMin) fMin = fElev; if (fElev > fMax) fMax = fElev; } float fDiff = fMax - fMin; // if there's less than 50cm of depth, don't bother building // a foundation if (fDiff < 0.5f) continue; // Create and add a foundation level pNewLev = new vtLevel; pNewLev->m_iStories = 1; pNewLev->m_fStoryHeight = fDiff; bld->InsertLevel(0, pNewLev); bld->SetFootprint(0, foot); pNewLev->SetEdgeMaterial(BMAT_NAME_CEMENT); pNewLev->SetEdgeColor(RGBi(255, 255, 255)); built++; } VTLOG("%d added.\n", built); return built; }
/** * Use the height data in the grid and a colormap fill a bitmap with colors. * Any undefined heixels in the source will be fill with red (255,0,0). * * \param pBM The bitmap to be colored. * \param color_map A ColorMap which has already had GenerateColorTable() called. * \param nodata The color to use for NODATA areas, where there are no elevation values. * \param progress_callback If supplied, this function will be called back * with a value of 0 to 100 as the operation progresses. * * \return true if any invalid elevation values were encountered. */ bool vtHeightFieldGrid3d::ColorDibFromTable(vtBitmapBase *pBM, const ColorMap *color_map, const RGBAi &nodata, bool progress_callback(int)) const { VTLOG1(" ColorDibFromTable:"); const IPoint2 bitmap_size = pBM->GetSize(); int depth = pBM->GetDepth(); VTLOG(" dib size %d x %d, grid %d x %d.. ", bitmap_size.x, bitmap_size.y, m_iSize.x, m_iSize.y); const bool bExact = (bitmap_size == m_iSize); double ratiox = (double)(m_iSize.x - 1)/(bitmap_size.x - 1), ratioy = (double)(m_iSize.y - 1)/(bitmap_size.y - 1); bool has_invalid = false; const RGBi nodata_24bit(nodata.r, nodata.g, nodata.b); float elev; // now iterate over the texels for (int i = 0; i < bitmap_size.x; i++) { if (progress_callback != NULL && (i&40) == 0) progress_callback(i * 100 / bitmap_size.x); // find the corresponding location in the height grid const double x = i * ratiox; for (int j = 0; j < bitmap_size.y; j++) { const double y = j * ratioy; if (bExact) elev = GetElevation(i, j, true); // Always use true elevation else elev = GetInterpolatedElevation(x, y, true); // Always use true elevation if (elev == INVALID_ELEVATION) { if (depth == 32) pBM->SetPixel32(i, bitmap_size.y - 1 - j, nodata); else pBM->SetPixel24(i, bitmap_size.y - 1 - j, nodata_24bit); has_invalid = true; continue; } const RGBi &rgb = color_map->ColorFromTable(elev); if (depth == 32) pBM->SetPixel32(i, bitmap_size.y - 1 - j, rgb); else pBM->SetPixel24(i, bitmap_size.y - 1 - j, rgb); } } VTLOG("Done.\n"); return has_invalid; }
/** * Attempt to read TIN data from a DXF file. */ bool vtTin::ReadDXF(const char *fname, bool progress_callback(int)) { VTLOG("vtTin::ReadDXF():\n"); std::vector<DxfEntity> entities; std::vector<DxfLayer> layers; DxfParser parser(fname, entities, layers); bool bSuccess = parser.RetrieveEntities(progress_callback); if (!bSuccess) { VTLOG(parser.GetLastError()); return false; } int vtx = 0; int found = 0; for (uint i = 0; i < entities.size(); i++) { const DxfEntity &ent = entities[i]; if (ent.m_iType == DET_3DFace || ent.m_iType == DET_Polygon) { int NumVerts = ent.m_points.size(); if (NumVerts == 3) { for (int j = 0; j < 3; j++) { DPoint2 p(ent.m_points[j].x, ent.m_points[j].y); float z = (float) ent.m_points[j].z; AddVert(p, z); } AddTri(vtx, vtx+1, vtx+2); vtx += 3; found ++; } } } VTLOG(" Found %d triangle entities, of type 3DFace or Polygon.\n", found); // If we didn't find any surfaces, we haven't got a TIN if (found == 0) return false; // Test each triangle for clockwisdom, fix if needed CleanupClockwisdom(); ComputeExtents(); return true; }
// // Elevations are slightly more complicated than other layers, because there // are two formats allowed for saving. This gets a bit messy, especially since // wxWidgets does not support our double extension (.bt.gz) syntax. // bool vtElevLayer::AskForSaveFilename() { wxString filter; if (m_pTin) filter = FSTRING_TIN; else filter = FSTRING_BT _T("|") FSTRING_BTGZ; wxString defaultFilename = GetLayerFilename(); // Beware: if the default filename is on a path that is no longer valid, // then (at leats on Win32) the file dialog won't open. Avoid this by // checking for validity first, and strip the path if needed. bool valid = wxFile::Access(defaultFilename, wxFile::read); if (!valid) defaultFilename = StartOfFilenameWX(defaultFilename); wxFileDialog saveFile(NULL, _("Save Layer"), _T(""), defaultFilename, filter, wxFD_SAVE | wxFD_OVERWRITE_PROMPT); // If user always wants to default to compressed, overwrite if (m_bDefaultGZip) m_bPreferGZip = true; saveFile.SetFilterIndex(m_pGrid && m_bPreferGZip ? 1 : 0); VTLOG("Asking user for elevation file name\n"); bool bResult = (saveFile.ShowModal() == wxID_OK); if (!bResult) return false; vtString fname = (const char *) saveFile.GetPath().mb_str(wxConvUTF8); VTLOG("Got filename: '%s'\n", (const char *) fname); if (m_pGrid) { m_bPreferGZip = (saveFile.GetFilterIndex() == 1); // work around incorrect extension(s) that wxFileDialog added RemoveFileExtensions(fname); if (m_bPreferGZip) fname += ".bt.gz"; else fname += ".bt"; } SetLayerFilename(wxString(fname, wxConvUTF8)); m_bNative = true; return true; }
bool vtImage::_Read(const char *fname, bool bAllowCache, bool progress_callback(int)) { #if LOG_IMAGE_LOAD VTLOG(" vtImage::Read(%s)\n", fname); #endif setName(fname); if (!stricmp(fname + strlen(fname) - 3, "bmp")) { vtDIB dib; if (dib.ReadBMP(fname)) { if (dib.GetDepth() == 8) { // We are presumably going to use this for a texture, and we // don't want to worry about 8-bit color paletted textures. vtDIB dib2; dib2.Create24From8bit(dib); _CreateFromDIB(&dib2); } else _CreateFromDIB(&dib); } } else if (!stricmp(fname + strlen(fname) - 3, "jpg")) { vtDIB pDIB; if (pDIB.ReadJPEG(fname)) { _CreateFromDIB(&pDIB); } } else if (!stricmp(fname + strlen(fname) - 3, "png")) { _ReadPNG(fname); } else if (!stricmp(fname + strlen(fname) - 3, "tif") || !stricmp(fname + strlen(fname) - 4, "tiff")) { _ReadTIF(fname, progress_callback); } else { return false; } #if LOG_IMAGE_LOAD VTLOG(" succeeded.\n"); #endif }
void MyTreeCtrl::RefreshTreeStatus(Builder *pBuilder) { VTLOG("(Refreshing Tree Status)\n"); wxTreeItemId root = GetRootItem(); wxTreeItemId parent, item; wxTreeItemIdValue cookie; for (parent = GetFirstChild(root, cookie); parent; parent = GetNextChild(root, cookie)) { wxTreeItemIdValue cookie2; for (item = GetFirstChild(parent, cookie2); item; item = GetNextChild(parent, cookie2)) { MyTreeItemData *data = (MyTreeItemData *)GetItemData(item); if (data) { SetItemText(item, MakeItemName(data->m_pLayer)); if (data->m_pLayer == pBuilder->GetActiveLayer()) SelectItem(item); if (data->m_pLayer->GetVisible()) { SetItemFont(item, *wxNORMAL_FONT); SetItemTextColour(item, wxColour(0,0,0)); } else { SetItemFont(item, *wxITALIC_FONT); SetItemTextColour(item, wxColour(80,80,80)); } } } } }
EnviroFrame::~EnviroFrame() { VTLOG("Deleting Frame\n"); m_mgr.UnInit(); DeleteCanvas(); delete m_pSceneGraphDlg; delete m_pPlantDlg; delete m_pFenceDlg; delete m_pTagDlg; delete m_pUtilDlg; delete m_pCameraDlg; delete m_pLocationDlg; delete m_pInstanceDlg; delete m_pLayerDlg; #ifdef VTP_NVIDIA_PERFORMANCE_MONITORING delete m_pPerformanceMonitorDlg; #endif delete m_pVIADlg; delete m_pStatusBar; delete m_pToolbar; SetStatusBar(NULL); }
void EnviroFrame::LoadLayer(vtString &fname) { VTLOG("EnviroFrame::LoadLayer '%s'\n", (const char *) fname); bool success = false; if (g_App.m_state == AS_Terrain) { vtTerrain *pTerr = g_App.GetCurrentTerrain(); OpenProgressDialog(_("Loading..."), wxString::FromUTF8(fname), false, this); pTerr->SetProgressCallback(progress_callback); success = LoadTerrainLayer(fname); CloseProgressDialog(); } else if (g_App.m_state == AS_Orbit) { // earth view int ret = g_App.AddGlobeAbstractLayer(fname); if (ret == -1) wxMessageBox(_("Couldn't open")); else if (ret == -2) wxMessageBox(_("That file isn't point data.")); else success = true; } if (success) m_pLayerDlg->RefreshTreeContents(); }
void EnviroGUI::SetState(AppState s) { // if entering or leaving terrain or orbit state AppState previous = m_state; m_state = s; if (m_state != previous) { VTLOG("Changing app state from %s to %s\n", AppStateNames[previous], AppStateNames[m_state]); GetFrame()->SetTitle(wxGetApp().MakeFrameTitle(GetCurrentTerrain())); } if ((previous == AS_Terrain && m_state != AS_Terrain) || (previous == AS_Orbit && m_state != AS_Orbit) || (previous != AS_Terrain && m_state == AS_Terrain) || (previous != AS_Orbit && m_state == AS_Orbit)) { GetFrame()->RefreshToolbar(); } if (s == AS_Error) { // If we encounter an error while trying to open a terrain, don't get // stuck in a progress dialog. CloseProgressDialog2(); } }
bool vtStructureArray::WriteXML(const char* filename, bool bGZip) const { VTLOG("WriteXML(%s)\n", filename); // Avoid trouble with '.' and ',' in Europe LocaleWrap normal_numbers(LC_NUMERIC, "C"); GZOutput out(bGZip); if (!gfopen(out, filename)) { throw xh_io_exception("Could not open output file", xh_location(filename), "XML Writer"); } gfprintf(out, "<?xml version=\"1.0\"?>\n"); gfprintf(out, "\n"); gfprintf(out, "<StructureCollection xmlns=\"http://www.openplans.net\"\n" "\t\t\t\t\t xmlns:gml=\"http://www.opengis.net/gml\"\n" "\t\t\t\t\t xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n" "\t\t\t\t\t xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" "\t\t\t\t\t xsi:schemaLocation=\"http://www.openplans.net/buildings.xsd\">\n"); gfprintf(out, "\n"); // Write the extents (required by gml:StructureCollection) DRECT ext; GetExtents(ext); gfprintf(out, "\t<gml:boundedBy>\n"); gfprintf(out, "\t\t<gml:Box>\n"); gfprintf(out, "\t\t\t<gml:coordinates>"); gfprintf(out, "%.9lf,%.9lf %.9lf,%.9lf", ext.left, ext.bottom, ext.right, ext.top); gfprintf(out, "</gml:coordinates>\n"); gfprintf(out, "\t\t</gml:Box>\n"); gfprintf(out, "\t</gml:boundedBy>\n"); gfprintf(out, "\n"); // Write projection char *wkt; OGRErr err = m_proj.exportToWkt(&wkt); if (err != OGRERR_NONE) { throw xh_io_exception("Couldn't write CRS to file", xh_location(filename), "XML Writer"); } gfprintf(out, "\t<SRS>%s</SRS>\n", wkt); gfprintf(out, "\n"); OGRFree(wkt); bool bDegrees = (m_proj.IsGeographic() == 1); for (uint i = 0; i < GetSize(); i++) { vtStructure *str = GetAt(i); str->WriteXML(out, bDegrees); } gfprintf(out, "</StructureCollection>\n"); gfclose(out); return true; }
void vtIcoGlobe::Create(int iTriangleCount, vtImage **images, Style style) { VTLOG("vtIcoGlobe::Create\n"); m_style = style; CreateMeshMat(iTriangleCount); CreateCoreMaterials(); SetEarthMaterials(CreateMaterialsFromImages(images)); CreateNodes(); }
/** * Create the globe's geometry and nodes. * * \param iTriangleCount The desired triangle count of the entire globe. The * class will attempt to match this value as closely as possible with * the indicated tessellation. * \param strImagePrefix The base of the filename for the set of icosahedral * surface textures. For example, if your textures have the name * "geosphere_*.jpg", pass "geosphere_" * \param style Tessellation style, can be one of: * - GEODESIC A classic geodesic tiling based on subdividing the edges * of the icosahedron and gnomonically projecting them to the sphere. * - RIGHT_TRIANGLE An alternative approach where each face is * divided into right triangles recursively. * - DYMAX_UNFOLD Same as RIGHT_TRIANGLE but the faces are also placed * on seperate geometries so that the globe can be unfolded in the * Dymaxion style. */ void vtIcoGlobe::Create(int iTriangleCount, const vtString &strImagePrefix, Style style) { VTLOG("vtIcoGlobe::Create\n"); m_style = style; CreateMeshMat(iTriangleCount); CreateCoreMaterials(); SetEarthMaterials(CreateMaterialsFromFiles(strImagePrefix)); CreateNodes(); }
// // stoplights and stopsigns // void vtRoadMap3d::GenerateSigns(vtLodGrid *pLodGrid) { if (!pLodGrid) return; vtContentManager3d &con = vtGetContent(); osg::Node *stopsign = con.CreateNodeFromItemname("American Stopsign"); osg::Node *stoplight = con.CreateNodeFromItemname("Stoplight (right)"); if (!stopsign || !stoplight) { VTLOG("Couldn't find stopsign and stoplight.\n"); return; } for (NodeGeom *pN = GetFirstNode(); pN; pN = pN->GetNext()) { for (int r = 0; r < pN->NumLinks(); r++) { osg::Node *shape = NULL; if (pN->GetIntersectType(r) == IT_STOPSIGN && stopsign) { shape = (osg::Node *) stopsign->clone(osg::CopyOp::SHALLOW_COPY); } if (pN->GetIntersectType(r) == IT_LIGHT && stoplight) { shape = (osg::Node *) stoplight->clone(osg::CopyOp::SHALLOW_COPY); } if (!shape) continue; vtTransform *trans = new vtTransform; trans->addChild(shape); LinkGeom *link = pN->GetLink(r); FPoint3 unit = pN->GetUnitLinkVector(r); FPoint3 perp(unit.z, unit.y, -unit.x); FPoint3 offset; // Turn the sign (yaw) to face the oncoming traffic trans->RotateLocal(FPoint3(0,1,0), pN->GetLinkAngle(r) + PID2f); if (pN->GetIntersectType(r) == IT_STOPSIGN) { offset = pN->m_p3 + (unit * 6.0f) + (perp * (link->m_fRightWidth)); } if (pN->GetIntersectType(r) == IT_LIGHT) { offset = pN->m_p3 - (unit * 6.0f) + (perp * (link->m_fRightWidth)); } trans->Translate(offset); pLodGrid->AddToGrid(trans); } } }
vtElevLayer::vtElevLayer(const DRECT &area, const IPoint2 &size, bool bFloats, float fScale, const vtProjection &proj) : vtLayer(LT_ELEVATION) { SetupDefaults(); VTLOG(" Constructing vtElevLayer of size %d x %d, floats %d\n", size.x, size.y, bFloats); m_pTin = NULL; m_pGrid = new vtElevationGrid(area, size, bFloats, proj); if (!m_pGrid->HasData()) VTLOG1(" Grid allocation failed.\n"); m_pGrid->SetScale(fScale); }
bool vtUnzip::ExtractCurrentFile(FILE* file, void* buf, size_t size_buf) { bool bOK = true; while (bOK) { int bytes = ReadCurrentFile(buf,size_buf); if (bytes < 0) { VTLOG("error with zipfile in ReadCurrentFile\n"); bOK = false; } else if (bytes > 0) { if (fwrite(buf,bytes,1,file)!=1) { VTLOG("error in writing extracted file\n"); bOK = false; } } else break; } return bOK; }
bool vtUtilityMap::ReadXML(const char *pathname, bool progress_callback(int)) { // The locale might be set to something European that interprets '.' as ',' // and vice versa, which would break our usage of sscanf/atof terribly. // So, push the 'standard' locale, it is restored when it goes out of scope. LocaleWrap normal_numbers(LC_NUMERIC, "C"); bool success = false; UtilityVisitor visitor(this); try { readXML(pathname, visitor, progress_callback); success = true; } catch (xh_exception &ex) { // TODO: would be good to pass back the error message. VTLOG("XML Error: "); VTLOG(ex.getFormattedMessage().c_str()); return false; } return success; }
void EnviroFrame::ChangeFlightSpeed(float factor) { float speed = g_App.GetFlightSpeed(); g_App.SetFlightSpeed(speed * factor); VTLOG("Change flight speed to %f\n", speed * factor); m_pCameraDlg->GetValues(); m_pCameraDlg->ValuesToSliders(); m_pCameraDlg->TransferToWindow(); m_pCameraDlg->Refresh(); // Also set spacenavigator speed. Scaling from mouse to spacenav is // approximate, based on the magnitude and number of INPUT events the // spacenav appears to send, 100x seems to be rough correlation. m_canvas->SetSpaceNavSpeed(speed * factor / 100); }
/** * Create a new DIB in memory. */ bool vtDIB::Create(const IPoint2 &size, int bitdepth, bool create_palette) { m_iWidth = size.x; m_iHeight = size.y; m_iBitCount = bitdepth; m_iByteCount = m_iBitCount/8; _ComputeByteWidth(); int ImageSize = m_iByteWidth * m_iHeight; int PaletteColors = create_palette ? 256 : 0; m_iPaletteSize = sizeof(RGBQUAD) * PaletteColors; int total_size = sizeof(BITMAPINFOHEADER) + m_iPaletteSize + ImageSize; m_pDIB = malloc(total_size); if (!m_pDIB) { VTLOG("Could not allocate %d bytes\n", total_size); return false; } m_Hdr = (BITMAPINFOHEADER *) m_pDIB; m_Data = ((byte *)m_Hdr) + sizeof(BITMAPINFOHEADER) + m_iPaletteSize; m_Hdr->biSize = sizeof(BITMAPINFOHEADER); m_Hdr->biWidth = size.x; m_Hdr->biHeight = size.y; m_Hdr->biPlanes = 1; m_Hdr->biBitCount = (word) bitdepth; m_Hdr->biCompression = BI_RGB; m_Hdr->biSizeImage = ImageSize; m_Hdr->biClrUsed = PaletteColors; m_Hdr->biClrImportant = 0; if (create_palette) { RGBQUAD *rgb=(RGBQUAD*)((char*)m_Hdr + sizeof(BITMAPINFOHEADER)); for (int i=0; i<256; i++) rgb[i].rgbBlue = rgb[i].rgbGreen = rgb[i].rgbRed = (uchar)i; } m_bLeaveIt = false; return true; }
// Frame constructor vtFrame::vtFrame(wxFrame *parent, const wxString& title, const wxPoint& pos, const wxSize& size, long style): wxFrame(parent, -1, title, pos, size, style) { VTLOG(" constructing Frame (%x, title, pos, size, %x)\n", parent, style); m_bCloseOnIdle = false; // We definitely want full color and a 24-bit Z-buffer! int gl_attrib[7] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, WX_GL_BUFFER_SIZE, 24, WX_GL_DEPTH_SIZE, 24, 0 }; // Make a vtGLCanvas VTLOG1(" creating canvas\n"); m_canvas = new SimpleCanvas(this, -1, wxPoint(0, 0), wxSize(-1, -1), 0, _T("SimpleCanvas"), gl_attrib); // Show the frame Show(true); }
bool EnviroGUI::SaveStructures(bool bAskFilename) { VTLOG1("EnviroGUI::SaveStructures\n"); vtStructureLayer *st_layer = GetCurrentTerrain()->GetStructureLayer(); vtString fname = st_layer->GetFilename(); if (bAskFilename) { // save current directory wxString path = wxGetCwd(); wxString default_file(StartOfFilename(fname), wxConvUTF8); wxString default_dir(ExtractPath(fname, false), wxConvUTF8); EnableContinuousRendering(false); wxFileDialog saveFile(NULL, _("Save Built Structures Data"), default_dir, default_file, FSTRING_VTST, wxFD_SAVE | wxFD_OVERWRITE_PROMPT); bool bResult = (saveFile.ShowModal() == wxID_OK); EnableContinuousRendering(true); if (!bResult) { wxSetWorkingDirectory(path); // restore return false; } wxString str = saveFile.GetPath(); fname = str.mb_str(wxConvUTF8); st_layer->SetFilename(fname); } bool success = false; try { success = st_layer->WriteXML(fname); } catch (xh_io_exception &e) { string str = e.getFormattedMessage(); VTLOG(" Error: %s\n", str.c_str()); wxMessageBox(wxString(str.c_str(), wxConvUTF8), _("Error")); } if (success) st_layer->SetModified(false); return success; }
void App::display() { static int frame = 0; if (frame < 10) { frame++; VTLOG("Frame %d: ", frame); const GLubyte *ver = glGetString(GL_VERSION); if (ver != NULL) VTLOG1("Has context\n"); else { VTLOG1("No context\n"); return; } } vtGetScene()->DoUpdate(); // calls viewer->frame, etc. SDL_GL_SwapBuffers(); }
int vtElevLayer::SetUnknown(float fValue, const DRECT *area) { if (!m_pGrid) return 0; const IPoint2 &Size = m_pGrid->GetDimensions(); const DRECT &ext = m_pGrid->GetEarthExtents(); const DPoint2 &step = m_pGrid->GetSpacing(); int count = 0; DPoint2 p; bool bUseArea = (area && !area->IsEmpty()); for (int i = 0; i < Size.x; i++) { p.x = ext.left + (i * step.x); for (int j = 0; j < Size.y; j++) { p.y = ext.bottom + (j * step.y); // If an area was passed, restrict ourselves to use it if (bUseArea) { if (!area->ContainsPoint(p)) continue; } if (j == 0) VTLOG(" val %f ", m_pGrid->GetFValue(i, j)); if (m_pGrid->GetFValue(i, j) == INVALID_ELEVATION) { m_pGrid->SetFValue(i, j, fValue); count++; } } } return count; }
bool DConvert(FILE *fp, int length, double &value, bool bDebug=false) { char szCharString[64]; if (fread(szCharString, length, 1, fp) != 1) return false; szCharString[length] = 0; #ifndef _MSC_VER // Microsoft's C standard library documentation says that the exponent in // an atof() call can be {d,D,e,E}. The ANSI C standard seems to agree. // But Unix and MacOSX don't like {d,D}. So, for them, change it. for (int i=0; i < length; i++) if (szCharString[i] == 'D' || szCharString[i] == 'd') szCharString[i] = 'E'; #endif value = atof(szCharString); if (bDebug) VTLOG(" DConvert '%s' -> %lf\n", szCharString, value); return true; }
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::CreateUI() { VTLOG1("Frame window: creating menus and toolbars.\n"); CreateMenus(); // Create StatusBar m_pStatusBar = new MyStatusBar(this); SetStatusBar(m_pStatusBar); m_pStatusBar->Show(); m_pStatusBar->UpdateText(); PositionStatusBar(); #ifdef VTP_NVIDIA_PERFORMANCE_MONITORING // Stop crash in update toolbar m_pCameraDlg = NULL; m_pLocationDlg = NULL; m_pLODDlg = NULL; m_pPerformanceMonitorDlg = NULL; #endif // An array of values to tell wxWidgets how to make our OpenGL context. std::vector<int> gl_attribs; gl_attribs.push_back(WX_GL_RGBA); // Full color gl_attribs.push_back(WX_GL_DOUBLEBUFFER); gl_attribs.push_back(WX_GL_BUFFER_SIZE); // 24-bit Z-buffer gl_attribs.push_back(24); gl_attribs.push_back(WX_GL_DEPTH_SIZE); gl_attribs.push_back(24); VTLOG("Anti-aliasing multisamples: %d\n", g_Options.m_iMultiSamples); #if wxCHECK_VERSION(2, 9, 0) if (g_Options.m_iMultiSamples > 0) { gl_attribs.push_back(WX_GL_SAMPLE_BUFFERS); gl_attribs.push_back(1); gl_attribs.push_back(WX_GL_SAMPLES); gl_attribs.push_back(g_Options.m_iMultiSamples); } #endif if (g_Options.m_bStereo && g_Options.m_iStereoMode == 1) // 1 = Quad-buffer stereo { gl_attribs.push_back(WX_GL_STEREO); } // Zero terminates the array gl_attribs.push_back(0); VTLOG("Frame window: creating view canvas.\n"); m_canvas = new EnviroCanvas(this, -1, wxPoint(0, 0), wxSize(-1, -1), 0, _T("vtGLCanvas"), &gl_attribs.front()); // Show the frame VTLOG("Showing the main frame\n"); Show(true); VTLOG("Constructing dialogs\n"); m_pBuildingDlg = new BuildingDlg3d(this, -1, _("Building Properties")); m_pCameraDlg = new CameraDlg(this, -1, _("Camera-View")); m_pDistanceDlg = new DistanceDlg3d(this, -1, _("Distance")); m_pEphemDlg = new EphemDlg(this, -1, _("Ephemeris")); m_pFenceDlg = new LinearStructureDlg3d(this, -1, _("Linear Structures")); m_pInstanceDlg = new InstanceDlg3d(this, this, -1, _("Instances"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); m_pTagDlg = new TagDlg(this, -1, _("Tags"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); m_pTagDlg->SetSize(440,80); m_pLODDlg = new LODDlg(this, -1, _("Terrain LOD Info"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); // m_pLODDlg->Show(); // Enable this to see the LOD dialog immediately m_pPlantDlg = new PlantDlg(this, -1, _("Plants")); m_pPlantDlg->ShowOnlyAvailableSpecies(g_Options.m_bOnlyAvailableSpecies); m_pPlantDlg->SetLang(wxGetApp().GetLanguageCode()); m_pLocationDlg = new LocationDlg(this, -1, _("Locations"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); m_pSceneGraphDlg = new SceneGraphDlg(this, -1, _("Scene Graph"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); m_pSceneGraphDlg->SetSize(450, 600); m_pTimeDlg = new TimeDlg(this, -1, _("Time")); m_pUtilDlg = new UtilDlg(this, -1, _("Utility Poles")); m_pScenarioSelectDialog = new ScenarioSelectDialog(this, -1, _("Scenarios")); m_pVehicleDlg = new VehicleDlg(this, -1, _("Vehicles")); m_pDriveDlg = new DriveDlg(this); m_pProfileDlg = NULL; #ifdef VTP_NVIDIA_PERFORMANCE_MONITORING m_pPerformanceMonitorDlg = new CPerformanceMonitorDialog(this, wxID_ANY, _("Performance Monitor")); #endif m_pVIADlg = new VIADlg(this); #if wxVERSION_NUMBER < 2900 // before 2.9.0 if (m_canvas) m_canvas->SetCurrent(); #else // Still need to do a "SetCurrent" here? It's more complicated now in wx 2.9.x, // and it's probably already taken care of by GraphicsWindowWX? #endif m_mgr.AddPane(m_canvas, wxAuiPaneInfo(). Name(wxT("canvas")).Caption(wxT("Canvas")). CenterPane()); m_mgr.Update(); m_pLayerDlg = new LayerDlg(this, -1, _("Layers"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); m_pLayerDlg->SetSize(500, -1); m_mgr.AddPane(m_pLayerDlg, wxAuiPaneInfo(). Name(_T("layers")).Caption(_("Layers")). Left()); m_mgr.Update(); }
bool EnviroFrame::LoadTerrainLayer(vtString &fname) { VTLOG("LoadTerrainLayer '%s'\n", (const char *) fname); vtTerrain *pTerr = g_App.GetCurrentTerrain(); bool success = false; vtString ext = GetExtension(fname); if (!ext.CompareNoCase(".vtst")) { MakeRelativeToDataPath(fname, "BuildingData"); vtStructureLayer *st_layer = pTerr->NewStructureLayer(); st_layer->SetLayerName(fname); if (!st_layer->Load()) { VTLOG("\tCouldn't load structures.\n"); // Removing the layer deletes it, by dereference. pTerr->GetLayers().Remove(st_layer); } else { pTerr->CreateStructures(st_layer); success = true; } } else if (!ext.CompareNoCase(".vf")) { MakeRelativeToDataPath(fname, "PlantData"); vtVegLayer *v_layer = pTerr->LoadVegetation(fname); if (v_layer) success = true; } else if (!ext.CompareNoCase(".shp")) { bool bRelative = MakeRelativeToDataPath(fname, "PointData"); if (!bRelative) bRelative = MakeRelativeToDataPath(fname, ""); if (bRelative) VTLOG("Shortened path to '%s'\n", (const char *) fname); vtAbstractLayer *ab_layer = pTerr->NewAbstractLayer(); ab_layer->SetLayerName(fname); // TODO here: progress dialog on load? if (ab_layer->Load(pTerr->GetProjection(), NULL)) { VTLOG("Successfully read features from file '%s'\n", (const char *) fname); // Abstract layers aren't constructed yet, giving us a chance to ask // for styling. vtTagArray &props = ab_layer->Props(); StyleDlg dlg(NULL, -1, _("Style"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); dlg.SetFeatureSet(ab_layer->GetFeatureSet()); dlg.SetOptions(props); if (dlg.ShowModal() == wxID_OK) { // Copy all the style attributes to the new featureset VTLOG1(" Setting featureset properties.\n"); dlg.GetOptions(props); pTerr->CreateAbstractLayerVisuals(ab_layer); success = true; } } if (!success) { VTLOG("Couldn't read features from file '%s'\n", (const char *) fname); pTerr->RemoveLayer(ab_layer); } } else if (!ext.CompareNoCase(".itf")) { MakeRelativeToDataPath(fname, "Elevation"); vtTagArray tags; tags.SetValueString("Type", TERR_LTYPE_ELEVATION); tags.SetValueString("Filename", fname); tags.SetValueFloat(STR_OPACITY, 1.0f); tags.SetValueFloat(STR_GEOTYPICAL_SCALE, 10.0f); TinTextureDlg dlg(this, -1, _("TIN Texture")); dlg.SetOptions(tags); if (dlg.ShowModal() == wxID_OK) { dlg.GetOptions(tags); success = pTerr->CreateElevLayerFromTags(tags); } } else if (!ext.CompareNoCase(".tif")) { MakeRelativeToDataPath(fname, "GeoSpecific"); vtImageLayer *im_layer = pTerr->NewImageLayer(); im_layer->Props().SetValueString("Filename", fname); if (!im_layer->Load()) { VTLOG("\tCouldn't load image layer.\n"); // Removing the layer deletes it, by dereference. pTerr->GetLayers().Remove(im_layer); } else { pTerr->AddMultiTextureOverlay(im_layer); success = true; } } return success; }