예제 #1
0
BaselineRow::BaselineRow(double line_spacing, TO_ROW* to_row)
  : blobs_(to_row->blob_list()),
    baseline_pt1_(0.0f, 0.0f), baseline_pt2_(0.0f, 0.0f),
    baseline_error_(0.0), good_baseline_(false) {
  ComputeBoundingBox();
  // Compute a scale factor for rounding to ints.
  disp_quant_factor_ = kOffsetQuantizationFactor * line_spacing;
  fit_halfrange_ = kFitHalfrangeFactor * line_spacing;
  max_baseline_error_ = kMaxBaselineError * line_spacing;
}
예제 #2
0
// Sets up the start and vec members of the loop from the pos members.
void TESSLINE::SetupFromPos() {
  EDGEPT* pt = loop;
  do {
    pt->vec.x = pt->next->pos.x - pt->pos.x;
    pt->vec.y = pt->next->pos.y - pt->pos.y;
    pt = pt->next;
  } while (pt != loop);
  start = pt->pos;
  ComputeBoundingBox();
}
예제 #3
0
bool AnimaNode::FinalizeAfterRead(AnimaScene* scene)
{
	// Chiamo prima la funzione della classe base perchè si occupa di caricare i dati dei figli,
	// i quali mi sono necessari per calcolare il bounding box
	bool rv = AnimaSceneObject::FinalizeAfterRead(scene);

	if(rv)
		ComputeBoundingBox();
	
	return rv;
}
예제 #4
0
static RAD_Model RAD_ReadFile( const char *filename )
	// Read radiosity solution model from input file.
	// The axis-aligned bounding box is computed.
{
	char badFile[] = "Invalid input model file";

	// Open input file
	FILE *fp = fopen( filename, "r" );
	if ( fp == NULL ) 
		ShowFatalError( __FILE__, __LINE__, "Cannot open input model file \"%s\"", filename );

	RAD_Model m;

	if ( fscanf( fp, "%d", &(m.numQuads) ) != 1 || m.numQuads < 0 )
		ShowFatalError( __FILE__, __LINE__, "%s \"%s\"", badFile, filename );

	m.quads = (RAD_Quad *) CheckedMalloc( sizeof(RAD_Quad) * m.numQuads );

	float minIntensity = FLT_MAX;
	float maxIntensity = 0.0f;
	float max_rgb[3] = { 0.0f, 0.0f, 0.0f };

	for ( int q = 0; q < m.numQuads; q++ )
	{
		for ( int i = 0; i < 4; i++ )
		{
			float vert[3], rgb[3];

			if ( fscanf( fp, "%f %f %f", &vert[0], &vert[1], &vert[2] ) != 3 )
				ShowFatalError( __FILE__, __LINE__, "%s \"%s\"", badFile, filename );

			if ( fscanf( fp, "%f %f %f", &rgb[0], &rgb[1], &rgb[2] ) != 3 )
				ShowFatalError( __FILE__, __LINE__, "%s \"%s\"", badFile, filename );

			CopyArray3( m.quads[q].v[i], vert );
			CopyArray3( m.quads[q].rgb[i], rgb );

			float intensity = rgb[0] + rgb[1] + rgb[2];
			if ( intensity > maxIntensity ) maxIntensity = intensity;
			if ( intensity < minIntensity ) minIntensity = intensity;
			if ( rgb[0] > max_rgb[0] ) max_rgb[0] = rgb[0];
			if ( rgb[1] > max_rgb[1] ) max_rgb[1] = rgb[1];
			if ( rgb[2] > max_rgb[2] ) max_rgb[2] = rgb[2];
		}
	}

	fclose( fp );
	m.minIntensity = minIntensity;
	m.maxIntensity = maxIntensity;
	CopyArray3( m.max_rgb, max_rgb );
	ComputeBoundingBox( &m );
	return m;
}
예제 #5
0
float Floor::GetDepth()
{
	if(m_depth < 0)
	{
		if(!ComputeBoundingBox())
		{
			return 0.0f;
		}
		m_depth = abs(m_topRight.z - m_bottomLeft.z);
	}

	return m_depth;
}
예제 #6
0
float Floor::GetHeight()
{
	if(m_height < 0)
	{
		if(!ComputeBoundingBox())
		{
			return 0.0f;
		}
		m_height = abs(m_topRight.y - m_bottomLeft.y);
	}
	

	return m_height;
}
예제 #7
0
float Floor::GetWidth()
{
	if(m_width < 0)
	{
		if(!ComputeBoundingBox())
		{
			return 0.0f;
		}
		m_width = abs(m_topRight.x - m_bottomLeft.x);
	}
	

	return m_width;
}
예제 #8
0
파일: tstraigh.c 프로젝트: sharkcz/xtrkcad
void AdjustStraightEndPt( track_p t, EPINX_T inx, coOrd pos )
{
	if (GetTrkType(t) != T_STRAIGHT) {
		AbortProg( "AdjustLIneEndPt( %d, %d ) not on STRAIGHT %d\n",
				GetTrkIndex(t), inx, GetTrkType(t) );
		return;
	}
	UndoModify( t );
#ifdef VERBOSE
lprintf("adjustStraightEndPt T%d[%d] p=[%0.3f %0.3f]\n",
		GetTrkIndex(t), inx, pos.x, pos.y );
#endif
	SetTrkEndPoint( t, inx, pos, GetTrkEndAngle(t,inx));
	ComputeBoundingBox( t );
	CheckTrackLength( t );
}
예제 #9
0
파일: Mesh.cpp 프로젝트: deedum/GLGame
//-------------------------------------------------------------------------------------------------
// 境界球取得
//-------------------------------------------------------------------------------------------------
int ComputeBoundingSphere(MESH* mesh, VECTOR3 *pvCenter, float *pfRadius)
{
	VECTOR3		vecMin, vecMax ,vecLen, vecCenter;
	float		fMax, fRadius;
	int			i;

	if (mesh == NULL) return 0;
	if (pvCenter == NULL) pvCenter = &vecCenter;
	if (!ComputeBoundingBox(mesh, &vecMin, &vecMax)) return 0;
	pvCenter->x = (vecMin.x + vecMax.x) / 2.0f;
	pvCenter->y = (vecMin.y + vecMax.y) / 2.0f;
	pvCenter->z = (vecMin.z + vecMax.z) / 2.0f;
	fMax = 0.0f;
	for (i = 0; i < mesh->vnum; i++) {
		vecLen.x = mesh->vertex[i].x - pvCenter->x;
		vecLen.y = mesh->vertex[i].y - pvCenter->y;
		vecLen.z = mesh->vertex[i].z - pvCenter->z;
		fRadius = Vec3Length(&vecLen);
		if (fMax < fRadius) fMax = fRadius;
	}
	if (pfRadius) *pfRadius = fMax;
	return 1;
}
예제 #10
0
BoneBridgeCAL3D::BoneBridgeCAL3D(Skeleton& skeleton, CalBone* calBone, CalModel* calModel, int calBoneID)
   : mSkeleton(skeleton)
   , mpCalBone(calBone)
   , mpCalModel(calModel)
   , mCalBoneID(calBoneID)
{
   // create box first
   {
      CalCoreBone* coreBone = mpCalBone->getCoreBone();

      // start by computing our bounding box and our bounding box corners
      ComputeBoundingBox();
      std::vector<Vec3f> corners = ComputeBoundingBoxCorners(coreBone->getBoundingBox());

      Vec3f bbMin = FindMinBoundingBoxXYZ(corners);
      Vec3f bbMax = FindMaxBoundingBoxXYZ(corners);
      BoundingBox<3, float> bbox(bbMin, bbMax - bbMin);

      // don't allow any boxes of no area
      {
         Vec3f dimensions = bbox.GetDimensions();

         const bool no_volume = dimensions[X] <= 0 || dimensions[Y] <= 0 || dimensions[Z] <= 0;
         if (no_volume)
         {
            static const float kThinnest = 0.01f; //0.01f;
            // enforce a volume!
            bbox = BoundingBox<3, float>(bbox.GetMinimum(), Vec3f(
               dimensions[X] > 0 ? dimensions[X] : kThinnest,
               dimensions[Y] > 0 ? dimensions[Y] : kThinnest,
               dimensions[Z] > 0 ? dimensions[Z] : kThinnest));
         }
      }

      SetDimensions(bbox.GetDimensions());
   }
}
//
// Framework functions
//
bool Setup()
{
	HRESULT hr = 0;

	//
	// Load the XFile data.
	//
	ID3DXBuffer* adjBuffer  = 0;
	ID3DXBuffer* mtrlBuffer = 0;
	DWORD        numMtrls   = 0;

	hr = D3DXLoadMeshFromX(  
		"../media/object/bigship1.x",
		D3DXMESH_MANAGED,
		Device,
		&adjBuffer,
		&mtrlBuffer,
		0,
		&numMtrls,
		&Mesh);

	if(FAILED(hr))
	{
		::MessageBox(0, "D3DXLoadMeshFromX() - FAILED", 0, 0);
		return false;
	}

	//
	// Extract the materials, load textures.
	//

	if( mtrlBuffer != 0 && numMtrls != 0 )
	{
		D3DXMATERIAL* mtrls = (D3DXMATERIAL*)mtrlBuffer->GetBufferPointer();

		for(int i = 0; i < numMtrls; i++)
		{
			// the MatD3D property doesn't have an ambient value set
			// when its loaded, so set it now:
			mtrls[i].MatD3D.Ambient = mtrls[i].MatD3D.Diffuse;

			// save the ith material
			Mtrls.push_back( mtrls[i].MatD3D );

			// check if the ith material has an associative texture
			if( mtrls[i].pTextureFilename != 0 )
			{
				// yes, load the texture for the ith subset
				IDirect3DTexture9* tex = 0;
				D3DXCreateTextureFromFile(
					Device,
					mtrls[i].pTextureFilename,
					&tex);

				// save the loaded texture
				Textures.push_back( tex );
			}
			else
			{
				// no texture for the ith subset
				Textures.push_back( 0 );
			}
		}
	}
	byhj::Release<ID3DXBuffer*>(mtrlBuffer); // done w/ buffer

	//
	// Optimize the mesh.
	//

	hr = Mesh->OptimizeInplace(		
		D3DXMESHOPT_ATTRSORT |
		D3DXMESHOPT_COMPACT  |
		D3DXMESHOPT_VERTEXCACHE,
		(DWORD*)adjBuffer->GetBufferPointer(),
		0, 0, 0);

	byhj::Release<ID3DXBuffer*>(adjBuffer); // done w/ buffer

	if(FAILED(hr))
	{
		::MessageBox(0, "OptimizeInplace() - FAILED", 0, 0);
		return false;
	}

	//
	// Compute Bounding Sphere and Bounding Box.
	//

	byhj::BoundingSphere boundingSphere;
	byhj::BoundingBox    boundingBox;

	ComputeBoundingSphere(Mesh, &boundingSphere);
	ComputeBoundingBox(Mesh, &boundingBox);

	D3DXCreateSphere(
		Device,
		boundingSphere._radius,
		20,
		20,
		&SphereMesh,
		0);

	D3DXCreateBox(
		Device,
		boundingBox._max.x - boundingBox._min.x,
		boundingBox._max.y - boundingBox._min.y,
		boundingBox._max.z - boundingBox._min.z,
		&BoxMesh,
		0);

	//
	// Set texture filters.
	//

	Device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
	Device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
	Device->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);

	// 
	// Set Lights.
	//

	D3DXVECTOR3 dir(1.0f, -1.0f, 1.0f);
	D3DXCOLOR col(1.0f, 1.0f, 1.0f, 1.0f);
	D3DLIGHT9 light = byhj::InitDirectionalLight(&dir, &col);

	Device->SetLight(0, &light);
	Device->LightEnable(0, true);
	Device->SetRenderState(D3DRS_NORMALIZENORMALS, true);
	Device->SetRenderState(D3DRS_SPECULARENABLE, true);

	//
	// Set camera.
	//

	D3DXVECTOR3 pos(4.0f, 12.0f, -20.0f);
	D3DXVECTOR3 target(0.0f, 0.0f, 0.0f);
	D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);

	D3DXMATRIX V;
	D3DXMatrixLookAtLH(
		&V,
		&pos,
		&target,
		&up);

	Device->SetTransform(D3DTS_VIEW, &V);

	//
	// Set projection matrix.
	//

	D3DXMATRIX proj;
	D3DXMatrixPerspectiveFovLH(
		&proj,
		D3DX_PI * 0.5f, // 90 - degree
		(float)Width / (float)Height,
		1.0f,
		1000.0f);
	Device->SetTransform(D3DTS_PROJECTION, &proj);

	return true;
}
예제 #12
0
파일: quadmodel.cpp 프로젝트: 9gix/cg
QM_Model QM_ReadFile( const char *filename )
	// Read model from input file.
	// The output QM_Model has only QM_OrigQuad.
	// The axis-aligned bounding box is computed.
{
	char badFile[] = "Invalid input model file";
	char badEOF[] = "Unexpected end of file";
	char lineBuf[ MAX_LINE_LEN + 1 ];

	// Open input file
	FILE *fp = fopen( filename, "r" );
	if ( fp == NULL ) 
		ShowFatalError( __FILE__, __LINE__, "Cannot open input model file \"%s\"", filename );

	int lineNum = 0;

//=== VERTICES ===

	int numVertices = 0;
	float *vertexTable = NULL;  // An array of 3D vertices.

	// Read number of vertices.
	if ( !ReadDataLine( lineBuf, &lineNum, filename, fp ) )
		ShowFatalError( __FILE__, __LINE__, "%s \"%s\"", badEOF, filename );

	if ( sscanf( lineBuf, "%d", &numVertices ) != 1  ||  numVertices < 0 )
		ShowFatalError( __FILE__, __LINE__, "%s \"%s\" at line %d", badFile, filename, lineNum );

	vertexTable = (float *) CheckedMalloc( sizeof(float) * 3 * numVertices );

	// Read the vertices.
	for ( int v = 0; v < numVertices; v++ )
	{
		float x, y, z;

		if ( !ReadDataLine( lineBuf, &lineNum, filename, fp ) )
			ShowFatalError( __FILE__, __LINE__, "%s \"%s\"", badEOF, filename );

		if ( sscanf( lineBuf, "%f %f %f", &x, &y, &z ) != 3 )
			ShowFatalError( __FILE__, __LINE__, "%s \"%s\" at line %d", badFile, filename, lineNum );

		vertexTable[ 3 * v + 0 ] = x;
		vertexTable[ 3 * v + 1 ] = y;
		vertexTable[ 3 * v + 2 ] = z;
	}


//=== MATERIALS ===

	int numMaterials = 0;
	float *reflectivityTable = NULL;	// An array of RGB reflectivity values.
	float *emissionTable = NULL;		// An array of RGB emission values.

	// Read number of materials.
	if ( !ReadDataLine( lineBuf, &lineNum, filename, fp ) )
		ShowFatalError( __FILE__, __LINE__, "%s \"%s\"", badEOF, filename );

	if ( sscanf( lineBuf, "%d", &numMaterials ) != 1  ||  numMaterials < 0 )
		ShowFatalError( __FILE__, __LINE__, "%s \"%s\" at line %d", badFile, filename, lineNum );

	reflectivityTable = (float *) CheckedMalloc( sizeof(float) * 3 * numMaterials );
	emissionTable = (float *) CheckedMalloc( sizeof(float) * 3 * numMaterials );

	// Read the materials.
	for ( int m = 0; m < numMaterials; m++ )
	{
		float r, g, b;

		if ( !ReadDataLine( lineBuf, &lineNum, filename, fp ) )
			ShowFatalError( __FILE__, __LINE__, "%s \"%s\"", badEOF, filename );

		if ( sscanf( lineBuf, "%f %f %f", &r, &g, &b ) != 3 )
			ShowFatalError( __FILE__, __LINE__, "%s \"%s\" at line %d", badFile, filename, lineNum );

		reflectivityTable[ 3 * m + 0 ] = r;
		reflectivityTable[ 3 * m + 1 ] = g;
		reflectivityTable[ 3 * m + 2 ] = b;

		if ( !ReadDataLine( lineBuf, &lineNum, filename, fp ) )
			ShowFatalError( __FILE__, __LINE__, "%s \"%s\"", badEOF, filename );

		if ( sscanf( lineBuf, "%f %f %f", &r, &g, &b ) != 3 )
			ShowFatalError( __FILE__, __LINE__, "%s \"%s\" at line %d", badFile, filename, lineNum );

		emissionTable[ 3 * m + 0 ] = r;
		emissionTable[ 3 * m + 1 ] = g;
		emissionTable[ 3 * m + 2 ] = b;
	}


//=== SURFACES ===

	int numSurfaces = 0;
	QM_Surface *surfaceTable = NULL;	// An array of surfaces.

	// Read number of surfaces.
	if ( !ReadDataLine( lineBuf, &lineNum, filename, fp ) )
		ShowFatalError( __FILE__, __LINE__, "%s \"%s\"", badEOF, filename );

	if ( sscanf( lineBuf, "%d", &numSurfaces ) != 1  ||  numSurfaces < 0 )
		ShowFatalError( __FILE__, __LINE__, "%s \"%s\" at line %d", badFile, filename, lineNum );

	surfaceTable = (QM_Surface *) CheckedMalloc( sizeof(QM_Surface) * numSurfaces );

	// Read the surfaces.
	for ( int s = 0; s < numSurfaces; s++ )
	{
		QM_SurfaceInit( &surfaceTable[s] );

		int matID, numQuads;

		// Read material index.
		if ( !ReadDataLine( lineBuf, &lineNum, filename, fp ) )
			ShowFatalError( __FILE__, __LINE__, "%s \"%s\"", badEOF, filename );

		if ( sscanf( lineBuf, "%d", &matID ) != 1  ||  matID < 0 || matID >= numMaterials )
			ShowFatalError( __FILE__, __LINE__, "%s \"%s\" at line %d", badFile, filename, lineNum );

		CopyArray3( surfaceTable[s].reflectivity, &reflectivityTable[3*matID] );
		CopyArray3( surfaceTable[s].emission, &emissionTable[3*matID] );

		// Read number of quadrilaterals in the surface.
		if ( !ReadDataLine( lineBuf, &lineNum, filename, fp ) )
			ShowFatalError( __FILE__, __LINE__, "%s \"%s\"", badEOF, filename );

		if ( sscanf( lineBuf, "%d", &numQuads ) != 1  ||  numQuads < 0 )
			ShowFatalError( __FILE__, __LINE__, "%s \"%s\" at line %d", badFile, filename, lineNum );

		surfaceTable[s].numOrigQuads = numQuads;
		surfaceTable[s].origQuads = (QM_OrigQuad *) CheckedMalloc( sizeof(QM_OrigQuad) * numQuads );

		// Read vertex indices for each quadrilateral.
		for ( int q = 0; q < numQuads; q++ )
		{
			int vertID[4];

			if ( !ReadDataLine( lineBuf, &lineNum, filename, fp ) )
				ShowFatalError( __FILE__, __LINE__, "%s \"%s\"", badEOF, filename );

			if ( sscanf( lineBuf, "%d %d %d %d", &vertID[0], &vertID[1], &vertID[2], &vertID[3] ) != 4 || 
				 vertID[0] < 0 || vertID[0] >= numVertices || vertID[1] < 0 || vertID[1] >= numVertices ||
				 vertID[2] < 0 || vertID[2] >= numVertices || vertID[3] < 0 || vertID[3] >= numVertices )
				ShowFatalError( __FILE__, __LINE__, "%s \"%s\" at line %d", badFile, filename, lineNum );

			CopyArray3( surfaceTable[s].origQuads[q].v[0], &vertexTable[ 3*vertID[0] ] );
			CopyArray3( surfaceTable[s].origQuads[q].v[1], &vertexTable[ 3*vertID[1] ] );
			CopyArray3( surfaceTable[s].origQuads[q].v[2], &vertexTable[ 3*vertID[2] ] );
			CopyArray3( surfaceTable[s].origQuads[q].v[3], &vertexTable[ 3*vertID[3] ] );

			// Compute normal vector to the quadrilateral.
			VecTriNormal( surfaceTable[s].origQuads[q].normal, 
				          surfaceTable[s].origQuads[q].v[0], 
						  surfaceTable[s].origQuads[q].v[1], 
						  surfaceTable[s].origQuads[q].v[2] );
			VecNormalize( surfaceTable[s].origQuads[q].normal, surfaceTable[s].origQuads[q].normal );
		}
	}

	QM_Model model = QM_ModelInit();
	model.numSurfaces = numSurfaces;
	model.surfaces = surfaceTable;
	ComputeBoundingBox( &model );

	fclose( fp );
	free( vertexTable );
	free( reflectivityTable );
	free( emissionTable );
	return model;
}