예제 #1
0
void WriteString(FILE *fp, const vtString &str)
{
	short len = (short) str.GetLength();
	fwrite(&len, 2, 1, fp);
	const char *buf = (const char *)str;
	fwrite(buf, len, 1, fp);
}
예제 #2
0
파일: vtTin.cpp 프로젝트: kamalsirsa/vtp
bool vtTin::ReadADF(const char *fname, bool progress_callback(int))
{
	const vtString tnxy_name = fname;
	if (tnxy_name.Right(6) != "xy.adf")
		return false;

	vtString base = tnxy_name.Left(tnxy_name.GetLength()-6);
	vtString tnz_name = base + "z.adf";
	vtString tnod_name = base + "od.adf";

	FILE *fp1 = vtFileOpen(tnxy_name, "rb");
	FILE *fp2 = vtFileOpen(tnz_name, "rb");
	FILE *fp3 = vtFileOpen(tnod_name, "rb");
	if (!fp1 || !fp2 || !fp3)
		return false;

	fseek(fp1, 0, SEEK_END);
	const int length_xy = ftell(fp1);
	rewind(fp1);	// go back again
	uint num_points = length_xy / 16;	// X and Y, each 8 byte doubles

	fseek(fp2, 0, SEEK_END);
	const int length_z = ftell(fp2);
	rewind(fp2);	// go back again
	uint num_heights = length_z / 4;		// Z is a 4 byte float

	DPoint2 p;
	float z;
	for (uint i = 0; i < num_points; i++)
	{
		if ((i%200) == 0 && progress_callback != NULL)
			progress_callback(i * 40 / num_points);

		FRead(&p.x, DT_DOUBLE, 2, fp1, BO_BIG_ENDIAN, BO_LITTLE_ENDIAN);
		FRead(&z, DT_FLOAT, 1, fp2, BO_BIG_ENDIAN, BO_LITTLE_ENDIAN);
		AddVert(p, z);
	}

	fseek(fp3, 0, SEEK_END);
	const int length_od = ftell(fp3);
	rewind(fp3);	// go back again
	const uint num_faces = length_od / 12;		// A B C as 4-byte ints

	int v[3];
	for (uint i = 0; i < num_faces; i++)
	{
		if ((i%200) == 0 && progress_callback != NULL)
			progress_callback(40 + i * 40 / num_faces);

		FRead(v, DT_INT, 3, fp3, BO_BIG_ENDIAN, BO_LITTLE_ENDIAN);
		AddTri(v[0]-1, v[1]-1, v[2]-1);
	}

	fclose(fp1);
	fclose(fp2);
	fclose(fp3);

	// Cleanup: the ESRI TIN contains four "boundary" point far outside the
	//  extents (directly North, South, East, and West).  We should ignore
	//  those four points and the triangles connected to them.
	// It seems we can assume the four 'extra' vertices are the first four.
	m_vert.RemoveAt(0, 4);
	m_z.erase(m_z.begin(), m_z.begin() + 4);
	m_vert_normal.RemoveAt(0, 4);

	// Re-index the triangles
	uint total = m_tri.size()/3;
	for (uint i = 0; i < total; i++)
	{
		if ((i%200) == 0 && progress_callback != NULL)
			progress_callback(80 + i * 20 / total);

		// Remove any triangles which referenced this vertex
		if (m_tri[i*3 + 0] < 4 ||
			m_tri[i*3 + 1] < 4 ||
			m_tri[i*3 + 2] < 4)
		{
			m_tri.erase(m_tri.begin() + i*3, m_tri.begin() + i*3 + 3);
			i--;
			total--;
			continue;
		}
	}
	// For all other triangles, adjust the indices to reflect the removal
	for (uint i = 0; i < m_tri.size(); i++)
		m_tri[i] = m_tri[i] - 4;

	// Test each triangle for clockwisdom, fix if needed
	CleanupClockwisdom();

	ComputeExtents();

	return true;
}
예제 #3
0
//
// Helper Function: Convert all accented characters to unaccented.
//
vtString RemoveAccents(const vtString &strInput)
{
	vtString strOutput = "";

	int len = strInput.GetLength();
	for (int i = 0; i < len; i++)
	{
		uchar ch = (uchar) strInput.GetAt(i);
		switch (ch)
		{
			// do conversion from "ANSI western europe" character set
		case 0xc0:	// '�'
		case 0xc1:	// '�':
		case 0xc2:	// '�':
		case 0xc3:	// '�':
		case 0xc4:	// '�':
		case 0xc5:	// '�':
			strOutput += 'A';
			break;
		case 0xc7:	// '�':
			strOutput += 'C';
			break;
		case 0xc8:	// '�':
		case 0xc9:	// '�':
		case 0xca:	// '�':
		case 0xcb:	// '�':
			strOutput += 'E';
			break;
		case 0xcc:	// '�':
		case 0xcd:	// '�':
		case 0xce:	// '�':
		case 0xcf:	// '�':
			strOutput += 'I';
			break;
		case 0xd0:	// '�':
			strOutput += 'D';
			break;
		case 0xd1:	// '�':
			strOutput += 'N';
			break;
		case 0xd2:	// '�':
		case 0xd3:	// '�':
		case 0xd4:	// '�':
		case 0xd5:	// '�':
		case 0xd6:	// '�':
		case 0xd8:	// '�':
			strOutput += 'O';
			break;
		case 0xd9:	// '�':
		case 0xda:	// '�':
		case 0xdb:	// '�':
		case 0xdc:	// '�':
			strOutput += 'U';
			break;
		case 0xdd:	// '�':
			strOutput += 'Y';
			break;
		case 0xdf:	// '�':
			strOutput += 's';	// NOTE: converts to 'ss'
			strOutput += 's';
			break;
		case 0xe0:	// '�':
		case 0xe1:	// '�':
		case 0xe2:	// '�':
		case 0xe3:	// '�':
		case 0xe4:	// '�':
		case 0xe5:	// '�':
			strOutput += 'a';
			break;
		case 0xe7:	// '�':
			strOutput += 'c';
			break;
		case 0xe8:	// '�':
		case 0xe9:	// '�':
		case 0xea:	// '�':
		case 0xeb:	// '�':
			strOutput += 'e';
			break;
		case 0xec:	// '�':
		case 0xed:	// '�':
		case 0xee:	// '�':
		case 0xef:	// '�':
			strOutput += 'i';
			break;
		case 0xf1:	// '�':
			strOutput += 'n';
			break;
		case 0xf2:	// '�':
		case 0xf3:	// '�':
		case 0xf4:	// '�':
		case 0xf5:	// '�':
		case 0xf6:	// '�':
		case 0xf8:	// '�':
			strOutput += 'o';
			break;
		case 0xf9:	// '�':
		case 0xfa:	// '�':
		case 0xfb:	// '�':
		case 0xfc:	// '�':
			strOutput += 'u';
			break;
		case 0xfd:	// '�':
		case 0xff:	// '�':
			strOutput += 'y';
			break;

		// Also do conversion from old DOS character set - fortunately, they
		// (surprisingly) don't overlap with ANSI accented characters.
		case 0x83:	// '�' (ANSI '�')
		case 0x84:	// '�' (ANSI '�')
		case 0x85:	// '�' (ANSI '�')
		case 0x86:	// '�' (ANSI '�')
		case 0xa0:	// '�' (ANSI '�')
			strOutput += 'a';
			break;
		case 0x8b:	// '�' (ANSI '�')
		case 0x8c:	// '�' (ANSI '�')
		case 0x8d:	// '�' (ANSI '�')
		case 0xa1:	// '�' (ANSI '�')
			strOutput += 'i';
			break;
		case 0x81:	// '�' (ANSI '�')
		case 0x96:	// '�' (ANSI '�')
		case 0x97:	// '�' (ANSI '�')
		case 0xa3:	// '�' (ANSI '�')
			strOutput += 'u';
			break;
		case 0x82:	// '�' (ANSI '�')
		case 0x88:	// '�' (ANSI '�')
		case 0x89:	// '�' (ANSI '�')
		case 0x8a:	// '�' (ANSI '�')
			strOutput += 'e';
			break;
		case 0x93:	// '�' (ANSI '�')
		case 0x94:	// '�' (ANSI '�')
		case 0x95:	// '�' (ANSI '�')
		case 0xa2:	// '�' (ANSI '�')
			strOutput += 'o';
			break;
		case 0x8e:	// '�' (ANSI '�')
		case 0x8f:	// '�' (ANSI '�')
			strOutput += 'A';
			break;
		case 0x9a:	// '�' (ANSI '�')
			strOutput += 'U';
			break;
		case 0x90:	// '�' (ANSI '�')
			strOutput += 'E';
			break;
		case 0x99:	// '�' (ANSI '�')
			strOutput += 'O';
			break;
		case 0x87:	// '�' (ANSI '�')
			strOutput += 'c';
			break;
		case 0x80:	// '�' (ANSI '�')
			strOutput += 'C';
			break;
		case 0x98:	// '�' (ANSI '�')
			strOutput += 'y';
			break;
		case 0xa4:	// '�' (ANSI '�')
			strOutput += 'n';
			break;
		case 0xa5:	// '�' (ANSI '�')
			strOutput += 'N';
			break;
		default:
			strOutput += ch;
		}
	}
	return strOutput;
}