예제 #1
0
bool SetupDefaultStructures(const vtString &fname)
{
	if (fname != "")
	{
		if (g_DefaultStructures.ReadXML(fname))
			return true;
	}

	// else supply some internal defaults and let the user know the load failed
	vtBuilding *pBld = g_DefaultStructures.NewBuilding();
	vtLevel *pLevel;
	DPolygon2 DefaultFootprint; // Single edge
	DefaultFootprint.resize(1);
	DefaultFootprint[0].Append(DPoint2(0.0, 0.0));
	DefaultFootprint[0].Append(DPoint2(0.0, 1.0));

	// The default building is NOT a complete building
	// Alter the code here to set different hard coded
	// defaults for use in other operations
	// First set any structure tags needed
	//
	// NONE
	//
	// Now create the required number of levels
	// and set the values
	//
	// Level 0
	pLevel = pBld->CreateLevel(DefaultFootprint);
	pLevel->m_iStories = 1;
	pLevel->m_fStoryHeight = 3.20f;
	pLevel->SetEdgeMaterial(BMAT_NAME_PLAIN);
	pLevel->SetEdgeColor(RGBi(255,0,0)); // Red
	pLevel->GetEdge(0)->m_iSlope = 90;
	// Level 1
	pLevel = pBld->CreateLevel(DefaultFootprint);
	pLevel->m_iStories = 1;
	pLevel->m_fStoryHeight = 3.20f;
	pLevel->SetEdgeMaterial(BMAT_NAME_PLAIN);
	pLevel->SetEdgeColor(RGBi(255,240,225)); // Tan
	pLevel->GetEdge(0)->m_iSlope = 0;		 // Flat

	g_DefaultStructures.Append(pBld);

	return false;
}
예제 #2
0
/**
 * Transform the coodinates of this building (the footprints of
 * each level) by the given coordinate transformation.
 */
void vtBuilding::TransformCoords(OCT *trans)
{
	uint i, j;
	DPoint2 p;

	for (i = 0; i < m_Levels.GetSize(); i++)
	{
		vtLevel *pLev = m_Levels[i];

		DPolygon2 foot = pLev->GetFootprint();
		for (uint r = 0; r < foot.size(); r++)
		{
			DLine2 &footline = foot[r];
			uint iSize = footline.GetSize();
			for (j = 0; j < iSize; j++)
			{
				p = footline[j];
				trans->Transform(1, &p.x, &p.y);
				footline[j] = p;
			}
		}
		pLev->SetFootprint(foot);
	}
}
예제 #3
0
파일: VegLayer.cpp 프로젝트: kamalsirsa/vtp
void vtVegLayer::AddElementsFromLULC(vtLULCFile *pLULC)
{
	LULCSection *section;
	LULCPoly *poly;

	SetVegType(VLT_Density);

	//set projections
	vtProjection proj_new;
	proj_new.SetProjectionSimple(0, -1, EPSG_DATUM_WGS84);
	SetProjection(proj_new);

	// figure out the number of polygons in file
	uint size = 0;
	for (uint sec = 0; sec < pLULC->NumSections(); sec++)
	{
		section = pLULC->GetSection(sec);
		size = size + section->m_iNumPolys;
	}

	// Create density field
	m_field_density = m_pSet->AddField("Density", FT_Float);
	m_pSet->SetNumEntities(size);

	// get each poly from LULC file
	uint i, s, p, count = 0;
	float density=0;
	for (s = 0; s < pLULC->NumSections(); s++)
	{
		section = pLULC->GetSection(s);
		for (p = 0; p < section->m_iNumPolys; p++)
		{
			poly = section->m_pPoly + p;

			bool wild = false;
			switch (poly->Attribute)
			{
				case 42:	// forest
					wild = true;
					density = 1.0f;
					break;
				case 32:
				case 33:
					wild = true;
					density = 0.5;
					break;
				case 22:	// orchards
					wild = false;
					// no crops for now
					break;
				default:
					density = 0.0f;
					break;
			}
			DLine2 dline;
			dline.SetSize(poly->m_iCoords);

			// get Coords of LULCpoly and store as latlon, then save in VPoly
			for (i = 0; i < dline.GetSize(); i++)
				dline.SetAt(i, poly->m_p[i]);

			DPolygon2 dpoly;
			dpoly.push_back(dline);

			GetPS()->SetPolygon(count, dpoly);
			m_pSet->SetValue(count, m_field_density, density);

			count++;
		}
	}
}
예제 #4
0
void StructVisitorGML::startElement(const char *name, const XMLAttributes &atts)
{
	const char *attval;
	float f;

	// clear data at the start of each element
	m_data = "";

	if (m_state == 0 && !strcmp(name, "StructureCollection"))
	{
		m_state = 1;
		return;
	}

	if (m_state == 1)
	{
		if (!strcmp(name, "Building"))
		{
			m_pBuilding = m_pSA->NewBuilding();
			m_pStructure = m_pBuilding;
			m_state = 2;
			m_iLevel = 0;
		}
		else if (!strcmp(name, "Linear"))
		{
			m_pFence = m_pSA->NewFence();
			m_pFence->GetParams().Blank();
			m_pStructure = m_pFence;

			// support obsolete attribute
			attval = atts.getValue("Height");
			if (attval)
			{
				f = (float) atof(attval);
				m_pFence->GetParams().m_fPostHeight = f;
				m_pFence->GetParams().m_fConnectTop = f;
			}
			m_state = 10;
		}
		else if (!strcmp(name, "Imported"))
		{
			m_pInstance = m_pSA->NewInstance();
			m_pStructure = m_pInstance;

			m_state = 20;
		}
		attval = atts.getValue("ElevationOffset");
		if (attval)
			m_pStructure->SetElevationOffset((float) atof(attval));
		attval = atts.getValue("Absolute");
		if (attval)
			m_pStructure->SetAbsolute(*attval == 't');

		return;
	}

	if (m_state == 2)	// Building
	{
		if (!strcmp(name, "Level"))
		{
			m_pLevel = m_pBuilding->CreateLevel();
			attval = atts.getValue("FloorHeight");
			if (attval)
				m_pLevel->m_fStoryHeight = (float) atof(attval);
			attval = atts.getValue("StoryCount");
			if (attval)
				m_pLevel->m_iStories = atoi(attval);
			m_state = 3;
			m_iEdge = 0;
		}
		return;
	}

	if (m_state == 3)	// Level
	{
		if (!strcmp(name, "Footprint"))
		{
			m_state = 4;
			m_Footprint.clear();
		}
		else if (!strcmp(name, "Edge"))
		{
			m_pEdge = m_pLevel->GetEdge(m_iEdge);
			if (m_pEdge)	// safety check
			{
				m_pEdge->m_Features.clear();

				attval = atts.getValue("Material");
				if (attval)
				{
					vtMaterialDescriptorArray *mats = GetGlobalMaterials();
					m_pEdge->m_pMaterial = mats->FindName(attval);
					if (m_pEdge->m_pMaterial == NULL)
					{
						// What to do when a VTST references a material that
						// we don't have?  We don't want to lose the material
						// name information, and we also don't want to crash
						// later with a NULL material.  So, make a dummy.
						vtMaterialDescriptor *mat;
						mat = new vtMaterialDescriptor(attval, "", VT_MATERIAL_COLOUR);
						mat->SetRGB(RGBi(255,255,255));	// white means: missing
						mats->Append(mat);
						m_pEdge->m_pMaterial = &mat->GetName();
					}
				}
				attval = atts.getValue("Color");
				if (attval)
					m_pEdge->m_Color = ParseHexColor(attval);
				attval = atts.getValue("Slope");
				if (attval)
					m_pEdge->m_iSlope = atoi(attval);
				attval = atts.getValue("EaveLength");
				if (attval)
					m_pEdge->m_fEaveLength = (float) atof(attval);
				attval = atts.getValue("Facade");
				if (attval)
					m_pEdge->m_Facade = attval;
			}

			m_state = 7;	// in Edge
		}
		return;
	}

	if (m_state == 4)	// Footprint
	{
		if (!strcmp(name, "gml:outerBoundaryIs"))
			m_state = 5;
		if (!strcmp(name, "gml:innerBoundaryIs"))
			m_state = 6;
	}

	if (m_state == 5)	// Footprint outerBoundaryIs
	{
		// nothing necessary here, catch the end of element
	}

	if (m_state == 6)	// Footprint innerBoundaryIs
	{
		// nothing necessary here, catch the end of element
	}

	if (m_state == 7)	// Edge
	{
		if (!strcmp(name, "EdgeElement"))
		{
			vtEdgeFeature ef;

			attval = atts.getValue("Type");
			if (attval)
				ef.m_code = vtBuilding::GetEdgeFeatureValue(attval);
			attval = atts.getValue("Begin");
			if (attval)
				ef.m_vf1 = (float) atof(attval);
			attval = atts.getValue("End");
			if (attval)
				ef.m_vf2 = (float) atof(attval);
			if (m_pEdge)
				m_pEdge->m_Features.push_back(ef);
		}
	}

	if (m_state == 10)	// Linear
	{
		vtLinearParams &param = m_pFence->GetParams();
		if (!strcmp(name, "Path"))
		{
			m_state = 11;
		}
		else if (!strcmp(name, "Posts"))
		{
			// this linear structure has posts
			const char *type = atts.getValue("Type");
			if (type)
				param.m_PostType = type;
			else
				param.m_PostType = "none";

			const char *spacing = atts.getValue("Spacing");
			if (spacing)
				param.m_fPostSpacing = (float)atof(spacing);

			const char *height = atts.getValue("Height");
			if (height)
				param.m_fPostHeight = (float)atof(height);

			const char *size = atts.getValue("Size");
			if (size)
			{
				FPoint3 postsize;
				sscanf(size, "%f, %f", &postsize.x, &postsize.z);
				param.m_fPostWidth = postsize.x;
				param.m_fPostDepth = postsize.z;
			}

			const char *exten = atts.getValue("Extension");
			if (exten)
				param.m_PostExtension = exten;
		}
		else if (!strcmp(name, "Connect"))
		{
			const char *type = atts.getValue("Type");
			if (type)
			{
				// Older format version had string "none", "wire", or a material for type
				// Newer format has integer 0,1,2,3 for none,wire,simple,profile
				if (*type >= '0' && *type <= '9')
					param.m_iConnectType = atoi(type);
				else
				{
					// Convert old to new
					if (!strcmp(type, "none"))
						param.m_iConnectType = 0;
					else if (!strcmp(type, "wire"))
						param.m_iConnectType = 1;
					else
					{
						param.m_iConnectType = 2;
						param.m_ConnectMaterial = type;
					}
				}
			}
			else
				param.m_iConnectType = 0;

			attval = atts.getValue("Material");
			if (attval)
				param.m_ConnectMaterial = attval;

			attval = atts.getValue("Top");
			if (attval)
				param.m_fConnectTop = (float)atof(attval);
			attval = atts.getValue("Bottom");
			if (attval)
				param.m_fConnectBottom = (float)atof(attval);
			attval = atts.getValue("Width");
			if (attval)
				param.m_fConnectWidth = (float)atof(attval);
			attval = atts.getValue("Slope");
			if (attval)
				param.m_iConnectSlope = atoi(attval);
			attval = atts.getValue("ConstantTop");
			if (attval)
				param.m_bConstantTop = (*attval == 't');

			attval = atts.getValue("Profile");
			if (attval)
				param.m_ConnectProfile = attval;
		}
	}
	if (m_state == 20)	// Imported
	{
		if (!strcmp(name, "Location"))
		{
			m_state = 21;
		}
	}
}
예제 #5
0
void StructVisitorGML::endElement(const char *name)
{
	bool bGrabAttribute = false;
	const char *data = m_data.c_str();

	if (m_state == 7 && !strcmp(name, "Edge"))
	{
		m_iEdge++;
		m_state = 3;
	}
	else if (m_state == 6)	// inside Footprint innerBoundaryIs
	{
		if (!strcmp(name, "gml:coordinates"))
		{
			DLine2 line;
			DLine2FromString(data, line);
			m_Footprint.push_back(line);
		}
		else if (!strcmp(name, "gml:innerBoundaryIs"))
			m_state = 4;
	}
	else if (m_state == 5)	// inside Footprint outerBoundaryIs
	{
		if (!strcmp(name, "gml:coordinates"))
		{
			DLine2 line;
			DLine2FromString(data, line);
			m_Footprint.push_back(line);
		}
		else if (!strcmp(name, "gml:outerBoundaryIs"))
			m_state = 4;
	}
	else if (m_state == 4)	// inside Footprint
	{
		if (!strcmp(name, "Footprint"))
		{
			m_pLevel->SetFootprint(m_Footprint);
			m_state = 3;
		}
	}
	else if (m_state == 3 && !strcmp(name, "Level"))
	{
		m_state = 2;
		m_iLevel ++;
	}
	else if (m_state == 2)
	{
		if (!strcmp(name, "Building"))
		{
			m_state = 1;

			// do this once after we done adding levels
			m_pBuilding->DetermineLocalFootprints();

			m_pSA->Append(m_pStructure);
			m_pStructure = NULL;
		}
		else
			bGrabAttribute = true;
	}
	else if (m_state == 1 && (!strcmp(name, "SRS")))
	{
		m_pSA->m_proj.SetTextDescription("wkt", data);

		// This seems wrong - why would each .vtst file reset the global projection?
		// g_Conv.Setup(m_pSA->m_proj.GetUnits(), DPoint2(0,0));
	}
	else if (m_state == 10)
	{
		if (!strcmp(name, "Linear"))
		{
			m_state = 1;

			m_pSA->Append(m_pStructure);
			m_pStructure = NULL;
		}
	}
	else if (m_state == 11)
	{
		if (!strcmp(name, "gml:coordinates"))
		{
			DLine2 &fencepts = m_pFence->GetFencePoints();
			double x, y;
			while (sscanf(data, "%lf,%lf", &x, &y) == 2)
			{
				fencepts.Append(DPoint2(x,y));
				data = strchr(data, ' ');
				if (data)
					data++;
				else
					break;
			}
		}
		else if (!strcmp(name, "Path"))
			m_state = 10;
	}
	else if (m_state == 20)
	{
		if (!strcmp(name, "Imported"))
		{
			m_state = 1;
			m_pSA->Append(m_pStructure);
			m_pStructure = NULL;
		}
		else if (!strcmp(name, "Rotation"))
		{
			float fRot;
			sscanf(data, "%f", &fRot);
			m_pInstance->SetRotation(fRot);
		}
		else if (!strcmp(name, "Scale"))
		{
			float fScale;
			sscanf(data, "%f", &fScale);
			m_pInstance->SetScale(fScale);
		}
		else
			bGrabAttribute = true;
	}
	else if (m_state == 21)
	{
		if (!strcmp(name, "gml:coordinates"))
		{
			double x, y;
			sscanf(data, "%lf,%lf", &x, &y);
			m_pInstance->SetPoint(DPoint2(x,y));
		}
		else if (!strcmp(name, "Location"))
			m_state = 20;
	}

	// first check for Attribute nodes
	if (bGrabAttribute)
	{
		// save these elements as literal strings
		vtTag tag;
		tag.name = name;
		tag.value = data;
		m_pStructure->AddTag(tag);		// where does the tag go?
	}
}