Пример #1
0
void vtFence3d::LoadProfile()
{
	vtString path = FindFileOnPaths(vtGetDataPath(),
		"BuildingData/" + m_Params.m_ConnectProfile);
	if (path != "")
		LoadFLine2FromSHP(path, m_Profile);
	else
		m_Profile.Clear();
}
Пример #2
0
void InstanceDlg::OnBrowseModelFile( wxCommandEvent &event )
{
	wxString filter = _("3D Model files");
	filter += _T("|");
	AddType(filter, FSTRING_3DS);
	AddType(filter, FSTRING_DAE);
	AddType(filter, FSTRING_OBJ);
	AddType(filter, FSTRING_LWO);
	AddType(filter, FSTRING_FLT);
	AddType(filter, FSTRING_OSG);
	AddType(filter, FSTRING_IVE);
	filter += _T("|");
	filter += FSTRING_ALL;
	wxFileDialog SelectFile(this, _("Choose model file"),
							_T(""), _T(""), filter, wxFD_OPEN);
	if (SelectFile.ShowModal() != wxID_OK)
		return;

	// If model file can be found by mimicing the search strategy implemented by
	// vtStructInstance3d::CreateNode then remove the directory part of the path
	// so that paths are not stored unnecessarily
	wxFileName TargetModel(SelectFile.GetPath());
	wxString filepart = TargetModel.GetFullName();
	vtString FoundModel = FindFileOnPaths(vtGetDataPath(), filepart.mb_str(wxConvUTF8));
	if ("" != FoundModel)
	{
		GetModelFile()->SetValue(filepart);
		return;
	}
	wxString test = wxT("BuildingModels/") + filepart;
	FoundModel = FindFileOnPaths(vtGetDataPath(), test.mb_str(wxConvUTF8));
	if ("" != FoundModel)
	{
		GetModelFile()->SetValue(filepart);
		return;
	}
	// Otherwise, use the full absolute path
	GetModelFile()->SetValue(SelectFile.GetPath());
}
Пример #3
0
int vtRoadMap3d::_CreateMaterial(const char *texture_filename, bool bTransparency)
{
	vtString fname = "GeoTypical/";
	fname += texture_filename;
	vtString path = FindFileOnPaths(vtGetDataPath(), fname);
	if (path == "")
		return -1;

	osg::Image *image = LoadOsgImage(path);
	if (!image)
		return -1;

	int material_index = m_pMats->AddTextureMaterial(image, true, true, bTransparency,
		false, ROAD_AMBIENT, ROAD_DIFFUSE, 1.0f, TERRAIN_EMISSIVE);

	if (material_index == -1)
		return -1;

	// All the road textures repeat, so don't clamp.
	vtMaterial *pMaterial = m_pMats->at(material_index);
	pMaterial->SetClamp(false);

	return material_index;
}
Пример #4
0
void vtElevLayer::RenderBitmap()
{
	if (!m_pGrid)
		return;

	// flag as being rendered
	m_bNeedsDraw = false;

	// safety check
	if (m_ImageSize.x == 0 || m_ImageSize.y == 0)
		return;

	DetermineMeterSpacing();

	clock_t tm1 = clock();

#if 0
	// TODO: re-enable this friendly cancel behavior
	if (UpdateProgressDialog(j*100/m_ImageSize.y))
	{
		wxString msg = _("Turn off displayed elevation for elevation layers?");
		if (wxMessageBox(msg, _T(""), wxYES_NO) == wxYES)
		{
			m_draw.m_bShowElevation = false;
			CloseProgressDialog();
			return;
		}
		else
			ResumeProgressDialog();
	}
#endif
	ColorMap cmap;
	vtString cmap_fname = m_draw.m_strColorMapFile;
	vtString cmap_path = FindFileOnPaths(vtGetDataPath(), "GeoTypical/" + cmap_fname);
	bool bLoaded = false;
	if (cmap_path != "")
	{
		if (cmap.Load(cmap_path))
			bLoaded = true;
	}
	if (!bLoaded)
		SetupDefaultColors(cmap);

	bool has_invalid = m_pGrid->ColorDibFromElevation(m_pBitmap, &cmap,
		8000, RGBi(255,0,0), progress_callback_minor);

	if (m_draw.m_bShadingQuick)
		m_pGrid->ShadeQuick(m_pBitmap, SHADING_BIAS, true, progress_callback_minor);
	else if (m_draw.m_bShadingDot)
	{
		// Quick and simple sunlight vector
		FPoint3 light_dir = LightDirection(m_draw.m_iCastAngle, m_draw.m_iCastDirection);

		if (m_draw.m_bCastShadows)
			m_pGrid->ShadowCastDib(m_pBitmap, light_dir, 1.0f,
				m_draw.m_fAmbient, progress_callback_minor);
		else
			m_pGrid->ShadeDibFromElevation(m_pBitmap, light_dir, 1.0f,
				m_draw.m_fAmbient, m_draw.m_fGamma, true, progress_callback_minor);
	}

	m_pBitmap->ContentsChanged();

	if (has_invalid && m_draw.m_bDoMask)
	{
		m_pMask = new wxMask(*m_pBitmap->m_pBitmap, wxColour(255, 0, 0));
		m_pBitmap->m_pBitmap->SetMask(m_pMask);
		m_bHasMask = true;
	}
	else
		m_bHasMask = false;

	clock_t tm2 = clock();
	float time = ((float)tm2 - tm1)/CLOCKS_PER_SEC;
	VTLOG("RenderBitmap: %.3f seconds.\n", time);

	m_bBitmapRendered = true;
}
Пример #5
0
bool vtElevLayer::WriteElevationTileset(TilingOptions &opts, BuilderView *pView)
{
	// Avoid trouble with '.' and ',' in Europe
	ScopedLocale normal_numbers(LC_NUMERIC, "C");

	// Check that options are valid
	CheckCompressionMethod(opts);

	// grid size
	int base_tilesize = opts.lod0size;

	int gridcols, gridrows;
	m_pGrid->GetDimensions(gridcols, gridrows);

	DRECT area = m_pGrid->GetEarthExtents();
	DPoint2 tile_dim(area.Width()/opts.cols, area.Height()/opts.rows);
	DPoint2 cell_size = tile_dim / base_tilesize;

	const vtProjection &proj = m_pGrid->GetProjection();
	vtString units = GetLinearUnitName(proj.GetUnits());
	units.MakeLower();
	int zone = proj.GetUTMZone();
	vtString crs;
	if (proj.IsGeographic())
		crs = "LL";
	else if (zone != 0)
		crs = "UTM";
	else
		crs = "Other";

	// Try to create directory to hold the tiles
	vtString dirname = opts.fname;
	RemoveFileExtensions(dirname);
	if (!vtCreateDir(dirname))
		return false;

	// We won't know the exact height extents until the tiles have generated,
	//  so gather extents as we produce the tiles and write the INI later.
	float minheight = 1E9, maxheight = -1E9;

	ColorMap cmap;
	vtElevLayer::SetupDefaultColors(cmap);	// defaults
	vtString dirname_image = opts.fname_images;
	RemoveFileExtensions(dirname_image);
	if (opts.bCreateDerivedImages)
	{
		if (!vtCreateDir(dirname_image))
			return false;

		vtString cmap_fname = opts.draw.m_strColorMapFile;
		vtString cmap_path = FindFileOnPaths(vtGetDataPath(), "GeoTypical/" + cmap_fname);
		if (cmap_path == "")
			DisplayAndLog("Couldn't find color map.");
		else
		{
			if (!cmap.Load(cmap_path))
				DisplayAndLog("Couldn't load color map.");
		}
	}

	ImageGLCanvas *pCanvas = NULL;
#if USE_OPENGL
	wxFrame *frame = new wxFrame;
	if (opts.bCreateDerivedImages && opts.bUseTextureCompression && opts.eCompressionType == TC_OPENGL)
	{
		frame->Create(g_bld->m_pParentWindow, -1, _T("Texture Compression OpenGL Context"),
			wxPoint(100,400), wxSize(280, 300), wxCAPTION | wxCLIP_CHILDREN);
		pCanvas = new ImageGLCanvas(frame);
	}
#endif

	// make a note of which lods exist
	LODMap lod_existence_map(opts.cols, opts.rows);

	bool bFloat = m_pGrid->IsFloatMode();
	bool bJPEG = (opts.bUseTextureCompression && opts.eCompressionType == TC_JPEG);

	int i, j, lod;
	int total = opts.rows * opts.cols, done = 0;
	for (j = 0; j < opts.rows; j++)
	{
		for (i = 0; i < opts.cols; i++)
		{
			// We might want to skip certain tiles
			if (opts.iMinRow != -1 &&
				(i < opts.iMinCol || i > opts.iMaxCol ||
				 j < opts.iMinRow || j > opts.iMaxRow))
				continue;

			DRECT tile_area;
			tile_area.left = area.left + tile_dim.x * i;
			tile_area.right = area.left + tile_dim.x * (i+1);
			tile_area.bottom = area.bottom + tile_dim.y * j;
			tile_area.top = area.bottom + tile_dim.y * (j+1);

			int col = i;
			int row = opts.rows-1-j;

			// draw our progress in the main view
			if (pView)
				pView->ShowGridMarks(area, opts.cols, opts.rows, col, opts.rows-1-row);

			// Extract the highest LOD we need
			vtElevationGrid base_lod(tile_area, IPoint2(base_tilesize+1, base_tilesize+1),
				bFloat, proj);

			bool bAllInvalid = true;
			bool bAllZero = true;
			int iNumInvalid = 0;
			DPoint2 p;
			int x, y;
			for (y = base_tilesize; y >= 0; y--)
			{
				p.y = area.bottom + (j*tile_dim.y) + ((double)y / base_tilesize * tile_dim.y);
				for (x = 0; x <= base_tilesize; x++)
				{
					p.x = area.left + (i*tile_dim.x) + ((double)x / base_tilesize * tile_dim.x);

					float fvalue = m_pGrid->GetFilteredValue(p);
					base_lod.SetFValue(x, y, fvalue);

					if (fvalue == INVALID_ELEVATION)
						iNumInvalid++;
					else
					{
						bAllInvalid = false;

						// Gather height extents
						if (fvalue < minheight)
							minheight = fvalue;
						if (fvalue > maxheight)
							maxheight = fvalue;
					}
					if (fvalue != 0)
						bAllZero = false;
				}
			}
			// Increment whether we omit or not
			done++;

			// If there is no real data there, omit this tile
			if (bAllInvalid)
				continue;

			// Omit all-zero tiles (flat sea-level) if desired
			if (opts.bOmitFlatTiles && bAllZero)
				continue;

			// Now we know this tile will be included, so note the LODs present
			int base_tile_exponent = vt_log2(base_tilesize);
			lod_existence_map.set(i, j, base_tile_exponent, base_tile_exponent-(opts.numlods-1));

			if (iNumInvalid > 0)
			{
				UpdateProgressDialog2(done*99/total, 0, _("Filling gaps"));

				bool bGood;
				int method = g_Options.GetValueInt(TAG_GAP_FILL_METHOD);
				if (method == 1)
					bGood = base_lod.FillGaps(NULL, progress_callback_minor);
				else if (method == 2)
					bGood = base_lod.FillGapsSmooth(NULL, progress_callback_minor);
				else if (method == 3)
					bGood = (base_lod.FillGapsByRegionGrowing(2, 5, progress_callback_minor) != -1);
				if (!bGood)
					return false;

				opts.iNoDataFilled += iNumInvalid;
			}

			// Create a matching derived texture tileset
			if (opts.bCreateDerivedImages)
			{
				// Create a matching derived texture tileset
				vtDIB dib;
				base_lod.ComputeHeightExtents();

				if (opts.bImageAlpha)
				{
					dib.Create(IPoint2(base_tilesize, base_tilesize), 32);
					base_lod.ColorDibFromElevation(&dib, &cmap, 4000, RGBAi(0,0,0,0));
				}
				else
				{
					dib.Create(IPoint2(base_tilesize, base_tilesize), 24);
					base_lod.ColorDibFromElevation(&dib, &cmap, 4000, RGBi(255,0,0));
				}

				if (opts.draw.m_bShadingQuick)
					base_lod.ShadeQuick(&dib, SHADING_BIAS, true);
				else if (opts.draw.m_bShadingDot)
				{
					FPoint3 light_dir = LightDirection(opts.draw.m_iCastAngle,
						opts.draw.m_iCastDirection);

					// Don't cast shadows for tileset; they won't cast
					//  correctly from one tile to the next.
					base_lod.ShadeDibFromElevation(&dib, light_dir, 1.0f,
						opts.draw.m_fAmbient, opts.draw.m_fGamma, true);
				}

				for (int k = 0; k < opts.numlods; k++)
				{
					vtString fname = MakeFilenameDB(dirname_image, col, row, k);

					int tilesize = base_tilesize >> k;

					vtMiniDatabuf output_buf;
					output_buf.xsize = tilesize;
					output_buf.ysize = tilesize;
					output_buf.zsize = 1;
					output_buf.tsteps = 1;
					output_buf.SetBounds(proj, tile_area);

					int depth = dib.GetDepth() / 8;
					int iUncompressedSize = tilesize * tilesize * depth;
					uchar *rgb_bytes = (uchar *) malloc(iUncompressedSize);

					uchar *dst = rgb_bytes;
					if (opts.bImageAlpha)
					{
						RGBAi rgba;
						for (int ro = 0; ro < base_tilesize; ro += (1<<k))
							for (int co = 0; co < base_tilesize; co += (1<<k))
							{
								dib.GetPixel32(co, ro, rgba);
								*dst++ = rgba.r;
								*dst++ = rgba.g;
								*dst++ = rgba.b;
								*dst++ = rgba.a;
							}
					}
					else
					{
						RGBi rgb;
						for (int ro = 0; ro < base_tilesize; ro += (1<<k))
							for (int co = 0; co < base_tilesize; co += (1<<k))
							{
								dib.GetPixel24(co, ro, rgb);
								*dst++ = rgb.r;
								*dst++ = rgb.g;
								*dst++ = rgb.b;
							}
					}

					// Write and optionally compress the image
					WriteMiniImage(fname, opts, rgb_bytes, output_buf,
						iUncompressedSize, pCanvas);

					// Free the uncompressed image
					free(rgb_bytes);
				}
			}

			for (lod = 0; lod < opts.numlods; lod++)
			{
				int tilesize = base_tilesize >> lod;

				vtString fname = MakeFilenameDB(dirname, col, row, lod);

				// make a message for the progress dialog
				wxString msg;
				msg.Printf(_("Writing tile '%hs', size %dx%d"),
					(const char *)fname, tilesize, tilesize);
				UpdateProgressDialog2(done*99/total, 0, msg);

				vtMiniDatabuf buf;
				buf.SetBounds(proj, tile_area);
				buf.alloc(tilesize+1, tilesize+1, 1, 1, bFloat ? 2 : 1);
				float *fdata = (float *) buf.data;
				short *sdata = (short *) buf.data;

				DPoint2 p;
				for (int y = base_tilesize; y >= 0; y -= (1<<lod))
				{
					p.y = area.bottom + (j*tile_dim.y) + ((double)y / base_tilesize * tile_dim.y);
					for (int x = 0; x <= base_tilesize; x += (1<<lod))
					{
						p.x = area.left + (i*tile_dim.x) + ((double)x / base_tilesize * tile_dim.x);

						if (bFloat)
						{
							*fdata = base_lod.GetFilteredValue(p);
							fdata++;
						}
						else
						{
							*sdata = (short) base_lod.GetFilteredValue(p);
							sdata++;
						}
					}
				}
				if (buf.savedata(fname) == 0)
				{
					// what should we do if writing a tile fails?
				}
			}
		}
	}
Пример #6
0
vtMaterialArray *vtIcoGlobe::CreateMaterialsFromFiles(const vtString &strImagePrefix)
{
    vtMaterialArray *mats = new vtMaterialArray;

#if 0
    if (m_style == INDEPENDENT_GEODESIC)
    {
        int mat = 0;
        for (int pair = 0; pair < 10; pair++)
        {
            for (int j = 0; j < m_freq; j++)
                for (int i = 0; i < m_freq; i++)
                {
                    // TEMP for testing: pretty colors
                    float r = (pair+1) * (1.0f / 10);
                    float g = (j+1) * (1.0f / m_freq);
                    float b = (i+1) * (1.0f / m_freq);
                    m_globe_mat[mat++] = mats->AddRGBMaterial1(RGBf(r, g, b),
                                         true, true);
                }
        }
        return;
    }
#endif
    vtString base;
    vtString fname;
    vtString fullpath;

    bool bCulling = true;
    bool bLighting = false;
    int pair, index;
    for (pair = 0; pair < 10; pair++)
    {
        if (strImagePrefix == "")
        {
            m_globe_mat[pair] = m_white;
            continue;
        }
        int f1 = icosa_face_pairs[pair][0];
        int f2 = icosa_face_pairs[pair][1];

        base = "WholeEarth/";
        base += strImagePrefix;
        base += "_";

        fname.Format("%s%02d%02d.jpg", (const char *)base, f1+1, f2+1);
        VTLOG("\t texture: %s\n", (const char *)fname);

        fullpath = FindFileOnPaths(vtGetDataPath(), (const char *)fname);
        if (fullpath == "")
        {
            // try again with png
            fname.Format("%s%02d%02d.png", (const char *)base, f1+1, f2+1);
            VTLOG("\t texture: %s\n", (const char *)fname);
            fullpath = FindFileOnPaths(vtGetDataPath(), (const char *)fname);
        }
        if (fullpath == "")
        {
            VTLOG("\t\tnot found on data paths.\n");
            index = -1;
        }
        else
        {
            ImagePtr img = osgDB::readImageFile((const char *)fullpath);
            if (img.valid())
            {
                index = mats->AddTextureMaterial(img,
                                                 bCulling, bLighting,
                                                 GetDepth(img) == 32, false,	// transp, additive
                                                 0.1f, 1.0f, 1.0f, 0.0f,		// ambient, diffuse, alpha, emmisive
                                                 false, true, false);		// texgen, clamp, mipmap
            }
            else
                index = -1;
        }
        if (index == -1)
        {
            VTLOG("\t\ttexture load failed, using red material.\n");
            m_globe_mat[pair] = m_red;
        }
        else
            m_globe_mat[pair] = index;
    }
    return mats;
}