Пример #1
0
void MkLineShape::__Update(const MkSceneTransform* parentTransform)
{
	m_WorldVertices.Clear();
	m_WorldDepth = m_LocalDepth;
	m_AABR.Clear();

	if (!m_LocalVertices.Empty())
	{
		// transform
		if (parentTransform == NULL) // 부모 노드가 없음
		{
			m_WorldVertices = m_LocalVertices;
		}
		else // 자체 transform이 없으므로 부모 노드의 것을 그대로 사용
		{
			parentTransform->GetWorldVertices(m_LocalVertices, m_WorldVertices);
			m_WorldDepth += parentTransform->GetWorldDepth();
		}

		// aabb
		MkFloat2 minPt(m_WorldVertices[0]);
		MkFloat2 maxPt(m_WorldVertices[0]);

		MK_INDEXING_LOOP(m_WorldVertices, i)
		{
			const MkFloat2& vertex = m_WorldVertices[i];
			minPt.CompareAndKeepMin(vertex);
			maxPt.CompareAndKeepMax(vertex);
		}

		m_AABR.position = minPt;
		m_AABR.size = maxPt - minPt;
	}
}
Пример #2
0
void GroundPlane::projectFrustum( const Frustum& frustum, F32 squareSize, Point2F& outMin, Point2F& outMax )
{
   // Get the frustum's min and max XY coordinates.

   const Box3F bounds = frustum.getBounds();

   Point2F minPt( bounds.minExtents.x, bounds.minExtents.y );
   Point2F maxPt( bounds.maxExtents.x, bounds.maxExtents.y );

   // Round the min and max coordinates so they align on the grid.

   minPt.x -= mFmod( minPt.x, squareSize );
   minPt.y -= mFmod( minPt.y, squareSize );

   F32 maxDeltaX = mFmod( maxPt.x, squareSize );
   F32 maxDeltaY = mFmod( maxPt.y, squareSize );

   if( maxDeltaX != 0.0f )
      maxPt.x += ( squareSize - maxDeltaX );
   if( maxDeltaY != 0.0f )
      maxPt.y += ( squareSize - maxDeltaY );

   // Add a safezone, so we don't touch the clipping planes.

   minPt.x -= squareSize; minPt.y -= squareSize;
   maxPt.x += squareSize; maxPt.y += squareSize;

   outMin = minPt;
   outMax = maxPt;
}
void Enemies::CreateBoundingBox()
{
	//
	// Compute scene bounding box.
	//
	XMFLOAT3 minPt(+MathHelper::Infinity, +MathHelper::Infinity, +MathHelper::Infinity);
	XMFLOAT3 maxPt(-MathHelper::Infinity, -MathHelper::Infinity, -MathHelper::Infinity);
	for (UINT i = 0; i < mEnemyInstances.size(); ++i)
	{
		minPt.x = 0.0f;
		minPt.y = 0.0f;
		minPt.z = 0.0f;
		maxPt.x = 0.0f;
		maxPt.y = 0.0f;
		maxPt.z = 0.0f;

		for (UINT j = 0; j < mEnemyInstances[i].Model->BasicVertices.size(); ++j)
		{
			XMFLOAT3 P = mEnemyInstances[i].Model->BasicVertices[j].Pos;
			//////multiply all these by 7
			minPt.x = MathHelper::Min(minPt.x, P.x);
			minPt.y = MathHelper::Min(minPt.y, P.y);
			minPt.z = MathHelper::Min(minPt.z, P.z);
			maxPt.x = MathHelper::Max(maxPt.x, P.x);
			maxPt.y = MathHelper::Max(maxPt.y, P.y);
			maxPt.z = MathHelper::Max(maxPt.z, P.z);
		}

		XMMATRIX temp = XMLoadFloat4x4(&mEnemyInstances[i].World);
		enemyclass[i]->setWorld(mEnemyInstances[i].World);

		XMVECTOR Scale;
		XMVECTOR Position;
		XMVECTOR Rotation;

		XMMatrixDecompose(&Scale, &Rotation, &Position, temp);

		XMFLOAT3 tempPos;
		XMStoreFloat3(&tempPos, Position);

		LevelCollisions[i].Center = tempPos;
		LevelCollisions[i].Extents = XMFLOAT3(0.5f*(maxPt.x - minPt.x),
			0.5f*(maxPt.y - minPt.y),
			0.5f*(maxPt.z - minPt.z));

		LevelCollisions[i].collisionType = enemyclass[i]->getcollisiontype();
		FLOAT scale = enemyclass[i]->getScale();
		LevelCollisions[i].Extents.x = LevelCollisions[i].Extents.x * scale;
		LevelCollisions[i].Extents.y = LevelCollisions[i].Extents.y * scale;
		LevelCollisions[i].Extents.z = LevelCollisions[i].Extents.z * scale;

		EnemyBox.collisionType = 1;

		enemyclass[i]->setAABB(&LevelCollisions[i]);
	}
}
	box2f GraphPane::updateGraphBounds() {
		float2 minPt(std::numeric_limits<float>::max());
		float2 maxPt(std::numeric_limits<float>::min());
		for (GraphDataPtr& curve : curves) {
			for (float2& pt : curve->points) {
				minPt = aly::min(pt, minPt);
				maxPt = aly::max(pt, maxPt);
			}
		}
		graphBounds = box2f(minPt, maxPt - minPt);
		return graphBounds;
	}
Пример #5
0
void GroundPlane::projectFrustum( const Frustum& _frustum, F32 squareSize, Point2F& outMin, Point2F& outMax )
{
   // Go through all the frustum's corner points and mark
   // the min and max XY coordinates.

   // transform the frustum to plane object space
   Frustum frustum = _frustum;
   frustum.mulL( mWorldToObj );

   Point2F minPt( F32_MAX, F32_MAX );
   Point2F maxPt( F32_MIN, F32_MIN );

   for( U32 i = 0; i < Frustum::CornerPointCount; ++ i )
   {
      const Point3F& point = frustum.getPoint( i );
      
      if( point.x < minPt.x )
         minPt.x = point.x;
      if( point.y < minPt.y )
         minPt.y = point.y;

      if( point.x > maxPt.x )
         maxPt.x = point.x;
      if( point.y > maxPt.y )
         maxPt.y = point.y;
   }

   // Round the min and max coordinates so they align on the grid.

   minPt.x -= mFmod( minPt.x, squareSize );
   minPt.y -= mFmod( minPt.y, squareSize );

   F32 maxDeltaX = mFmod( maxPt.x, squareSize );
   F32 maxDeltaY = mFmod( maxPt.y, squareSize );

   if( maxDeltaX != 0.0f )
      maxPt.x += ( squareSize - maxDeltaX );
   if( maxDeltaY != 0.0f )
      maxPt.y += ( squareSize - maxDeltaY );

   // Add a safezone, so we don't touch the clipping planes.

   minPt.x -= squareSize; minPt.y -= squareSize;
   maxPt.x += squareSize; maxPt.y += squareSize;

   outMin = minPt;
   outMax = maxPt;
}
Пример #6
0
void Bvh::update(std::list<IModel*> &modelList)
{
    if(!bTree)
        return;

    primList.clear();
    
    Point3 minPt(POS_INF, POS_INF,POS_INF);
    Point3 maxPt(-POS_INF,-POS_INF,-POS_INF);
    myTriSize = 0;

    std::list<IModel*>::iterator model;
    std::list<IPrimitive*>::iterator p;

    for( model = modelList.begin(); model != modelList.end(); model++ )
    {
        myTriSize += (*model)->GetPrimitiveCount();

        // update uniform grids min and max values;
        minPt.X() = min((*model)->MinPoint().X(), minPt.X());
        minPt.Y() = min((*model)->MinPoint().Y(), minPt.Y());
        minPt.Z() = min((*model)->MinPoint().Z(), minPt.Z());

        maxPt.X() = max((*model)->MaxPoint().X(), maxPt.X());
        maxPt.Y() = max((*model)->MaxPoint().Y(), maxPt.Y());
        maxPt.Z() = max((*model)->MaxPoint().Z(), maxPt.Z());

        std::list<IPrimitive*>* pl = &(*model)->getPrimitiveList();
        for ( p = pl->begin(); p != pl->end(); p++ )
        {
            primList.push_back( (*p) );
        }
    }

    myBound = AABB( minPt, maxPt );
    unsigned int *temp = new unsigned int[myTriSize];
    // check as we go
    trace(0, temp, 0);
    delete [] temp;
    bTree[0].bound = myBound;
}
Пример #7
0
/*
 	Function:	UpdateHapticMapping
 	Usage:		UpdateHapticMapping(); 
 	---------------------------------------------------------------------------
 Use the current OpenGL viewing transforms to initialize a transform for the
 haptic device workspace so that it's properly mapped to world coordinates.
 */
void UpdateHapticMapping(void)
{
    GLdouble modelview[16];
    GLdouble projection[16];
    GLint viewport[4];

    glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
    glGetDoublev(GL_PROJECTION_MATRIX, projection);
    glGetIntegerv(GL_VIEWPORT, viewport);

    hlMatrixMode(HL_TOUCHWORKSPACE);
    hlLoadIdentity();
    
    /* fit haptic workspace to the bound of the deformable surface */
    hduVector3Dd minPt(-kSurfaceSize / 2.0, -kSurfaceSize / 2.0, -kSurfaceSize / 2.0);
    hduVector3Dd maxPt(kSurfaceSize / 2.0, kSurfaceSize / 2.0, kSurfaceSize / 2.0);
    hluFitWorkspaceBox(modelview, minPt, maxPt);

    /* compute cursor scale */
    mCursorScale = hluScreenToModelScale(modelview, projection, viewport);
    const int CURSOR_SIZE_PIXELS = 20;
    mCursorScale *= CURSOR_SIZE_PIXELS;
}
Пример #8
0
void srs_env_model::CCollisionGridPlugin::newMapDataCB(SMapWithParameters & par)
{
	// init projected 2D map:
	m_data->header.frame_id = par.frameId;
	m_data->header.stamp = par.currentTime;
	m_crawlDepth = par.treeDepth;
	bool sizeChanged(false);

	// TODO: move most of this stuff into c'tor and init map only once (adjust if size changes)
	double minX, minY, minZ, maxX, maxY, maxZ;
	par.map->getTree().getMetricMin(minX, minY, minZ);
	par.map->getTree().getMetricMax(maxX, maxY, maxZ);

	octomap::point3d minPt(minX, minY, minZ);
	octomap::point3d maxPt(maxX, maxY, maxZ);
	octomap::OcTreeKey minKey, maxKey, curKey;
	if (!par.map->getTree().genKey(minPt, minKey)){
	  ROS_ERROR("Could not create min OcTree key at %f %f %f", minPt.x(), minPt.y(), minPt.z());
	  return;
	}

	if (!par.map->getTree().genKey(maxPt, maxKey)){
	  ROS_ERROR("Could not create max OcTree key at %f %f %f", maxPt.x(), maxPt.y(), maxPt.z());
	  return;
	}
	par.map->getTree().genKeyAtDepth(minKey, par.treeDepth, minKey);
	par.map->getTree().genKeyAtDepth(maxKey, par.treeDepth, maxKey);

	ROS_DEBUG("MinKey: %d %d %d / MaxKey: %d %d %d", minKey[0], minKey[1], minKey[2], maxKey[0], maxKey[1], maxKey[2]);

	// add padding if requested (= new min/maxPts in x&y):
	double halfPaddedX = 0.5*m_minSizeX;
	double halfPaddedY = 0.5*m_minSizeY;
	minX = std::min(minX, -halfPaddedX);
	maxX = std::max(maxX, halfPaddedX);
	minY = std::min(minY, -halfPaddedY);
	maxY = std::max(maxY, halfPaddedY);
	minPt = octomap::point3d(minX, minY, minZ);
	maxPt = octomap::point3d(maxX, maxY, maxZ);

	octomap::OcTreeKey paddedMaxKey;
	if (!par.map->getTree().genKey(minPt, m_paddedMinKey)){
	  ROS_ERROR("Could not create padded min OcTree key at %f %f %f", minPt.x(), minPt.y(), minPt.z());
	  return;
	}
	if (!par.map->getTree().genKey(maxPt, paddedMaxKey)){
	  ROS_ERROR("Could not create padded max OcTree key at %f %f %f", maxPt.x(), maxPt.y(), maxPt.z());
	  return;
	}
	par.map->getTree().genKeyAtDepth(m_paddedMinKey, par.treeDepth, m_paddedMinKey);
	par.map->getTree().genKeyAtDepth(paddedMaxKey, par.treeDepth, paddedMaxKey);

	ROS_DEBUG("Padded MinKey: %d %d %d / padded MaxKey: %d %d %d", m_paddedMinKey[0], m_paddedMinKey[1], m_paddedMinKey[2], paddedMaxKey[0], paddedMaxKey[1], paddedMaxKey[2]);
	assert(paddedMaxKey[0] >= maxKey[0] && paddedMaxKey[1] >= maxKey[1]);

	m_multires2DScale = 1 << (par.treeDepth - m_crawlDepth);
	unsigned int newWidth = (paddedMaxKey[0] - m_paddedMinKey[0])/m_multires2DScale +1;
	unsigned int newHeight = (paddedMaxKey[1] - m_paddedMinKey[1])/m_multires2DScale +1;

	if (newWidth != m_data->info.width || newHeight != m_data->info.height)
	  sizeChanged = true;

	m_data->info.width = newWidth;
	m_data->info.height = newHeight;
	int mapOriginX = minKey[0] - m_paddedMinKey[0];
	int mapOriginY = minKey[1] - m_paddedMinKey[1];
	assert(mapOriginX >= 0 && mapOriginY >= 0);

	// might not exactly be min / max of octree:
	octomap::point3d origin;
	par.map->getTree().genCoords(m_paddedMinKey, m_crawlDepth, origin);
	double gridRes = par.map->getTree().getNodeSize(par.treeDepth);
	m_data->info.resolution = gridRes;
	m_data->info.origin.position.x = origin.x() - gridRes*0.5;
	m_data->info.origin.position.y = origin.y() - gridRes*0.5;

//	std::cerr << "Origin: " << origin << ", grid resolution: " << gridRes << ", computed origin: "<< mapOriginX << ".." << mapOriginY << std::endl;

	if (par.treeDepth != m_crawlDepth){
		m_data->info.origin.position.x -= par.resolution/2.0;
		m_data->info.origin.position.y -= par.resolution/2.0;
	}

	if (sizeChanged){
	  ROS_INFO("2D grid map size changed to %d x %d", m_data->info.width, m_data->info.height);
	  m_data->data.clear();
	  // init to unknown:
	  m_data->data.resize(m_data->info.width * m_data->info.height, -1);
	}

	tButServerOcTree & tree( par.map->getTree() );
	srs_env_model::tButServerOcTree::leaf_iterator it, itEnd( tree.end_leafs() );

	// Crawl through nodes
	for ( it = tree.begin_leafs(m_crawlDepth); it != itEnd; ++it)
	{
		// Node is occupied?
		if (tree.isNodeOccupied(*it))
		{
			handleOccupiedNode(it, par);
		}// Node is occupied?
		else
		{
			handleFreeNode( it, par );
		}

	} // Iterate through octree

	m_DataTimeStamp = par.currentTime;

	invalidate();
}
Пример #9
0
bool DuckHuntMain::Init()
{
	if (!D3DApp::Init())
		return false;

	// Must init Effects first since InputLayouts depend on shader signatures.
	Effects::InitAll(md3dDevice);
	InputLayouts::InitAll(md3dDevice);
	RenderStates::InitAll(md3dDevice);
	mCrosshair = new Crosshair(md3dDevice);
	mTexMgr.Init(md3dDevice);
	DuckHuntMain::ShowCursors(false);
	mSky = new Sky(md3dDevice, L"Textures/desertcube1024.dds", 5000.0f);
	mSmap = new ShadowMap(md3dDevice, SMapSize, SMapSize);
	Terrain::InitInfo tii;
	tii.HeightMapFilename = L"Textures/myT5.raw";
	tii.LayerMapFilename0 = L"Textures/grass.dds";
	tii.LayerMapFilename1 = L"Textures/darkdirt.dds";
	tii.LayerMapFilename2 = L"Textures/stone.dds";
	tii.LayerMapFilename3 = L"Textures/lightdirt.dds";
	tii.LayerMapFilename4 = L"Textures/snow.dds";
	tii.BlendMapFilename = L"Textures/blend.dds";
	tii.HeightScale = 50.0f;
	tii.HeightmapWidth = 2049;
	tii.HeightmapHeight = 2049;
	tii.CellSpacing = 0.5f;

	mTerrain.Init(md3dDevice, md3dImmediateContext, tii);
	//Sound
	result = FMOD::System_Create(&mSystem);
	result = mSystem->init(32, FMOD_INIT_NORMAL, 0);
	result = mSystem->createSound("Sounds/GunFire.wav", FMOD_DEFAULT, 0, &mGunFire);
	result = mGunFire->setMode(FMOD_LOOP_OFF);






	mCam.SetLens(0.25f*MathHelper::Pi, AspectRatio(), 1.0f, 1000.0f);
	mSsao = new Ssao(md3dDevice, md3dImmediateContext, mClientWidth, mClientHeight, mCam.GetFovY(), mCam.GetFarZ());

	BuildScreenQuadGeometryBuffers();

	testModelDuck = new BasicModel(md3dDevice, mTexMgr, "Models\\duck.obj", L"Textures\\DUCK.jpg");



	BasicModelInstance testInstanceDuck;
	BasicModelInstance testInstanceDuck2;
	BasicModelInstance testInstanceDuck3;
	BasicModelInstance testInstanceDuck4;

	testInstanceDuck.Model = testModelDuck;
	testInstanceDuck2.Model = testModelDuck;
	testInstanceDuck3.Model = testModelDuck;
	testInstanceDuck4.Model = testModelDuck;



	//Duck 1
	XMMATRIX modelScale = XMMatrixScaling(1.0f, 1.0f, -1.0f);
	XMMATRIX modelRot = XMMatrixRotationY(0.0f);
	XMMATRIX modelOffset = XMMatrixTranslation(0.0f, 0.0f, 0.0f);
	//Duck 2
	XMMATRIX modelScale2 = XMMatrixScaling(2.0f, 2.0f, -1.0f);
	XMMATRIX modelRot2 = XMMatrixRotationY(-1.0f);
	XMMATRIX modelOffset2 = XMMatrixTranslation(1.0f, 1.0f, -1.0f);
	//Duck3
	XMMATRIX modelScale3 = XMMatrixScaling(1.5f, 1.5f, 1.5f);
	XMMATRIX modelRot3 = XMMatrixRotationY(0.5f);
	XMMATRIX modelOffset3 = XMMatrixTranslation(2.0f, 1.0f, -1.0f);
	//Duck4
	XMMATRIX modelScale4 = XMMatrixScaling(0.5f, 0.5f, -1.0f);
	XMMATRIX modelRot4 = XMMatrixRotationY(1.0f);
	XMMATRIX modelOffset4 = XMMatrixTranslation(0.5f, 1.0f, -1.0f);


	//Duck 1
	XMStoreFloat4x4(&testInstanceDuck.World, modelScale*modelRot*modelOffset);
	mModelInstances.push_back(testInstanceDuck);

	//Duck 2
	XMStoreFloat4x4(&testInstanceDuck2.World, modelScale2*modelRot2*modelOffset2);
	mModelInstances.push_back(testInstanceDuck2);

	//Duck 3
	XMStoreFloat4x4(&testInstanceDuck3.World, modelScale3*modelRot3*modelOffset3);
	mModelInstances.push_back(testInstanceDuck3);

	//Duck 4
	XMStoreFloat4x4(&testInstanceDuck4.World, modelScale4*modelRot4*modelOffset4);
	mModelInstances.push_back(testInstanceDuck4);


	//create collision box
	for (unsigned i = 0; i < mModelInstances.size(); i++)
	{
		mModelInstances[i].Model->CreateCollisionBox(mModelInstances[i].Model->BasicVertices);
	}






	//
	// Compute scene bounding box.
	//

	XMFLOAT3 minPt(+MathHelper::Infinity, +MathHelper::Infinity, +MathHelper::Infinity);
	XMFLOAT3 maxPt(-MathHelper::Infinity, -MathHelper::Infinity, -MathHelper::Infinity);
	for (UINT i = 0; i < mModelInstances.size(); ++i)
	{
		for (UINT j = 0; j < mModelInstances[i].Model->BasicVertices.size(); ++j)
		{
			XMFLOAT3 P = mModelInstances[i].Model->BasicVertices[j].Pos;

			minPt.x = MathHelper::Min(minPt.x, P.x);
			minPt.y = MathHelper::Min(minPt.x, P.x);
			minPt.z = MathHelper::Min(minPt.x, P.x);

			maxPt.x = MathHelper::Max(maxPt.x, P.x);
			maxPt.y = MathHelper::Max(maxPt.x, P.x);
			maxPt.z = MathHelper::Max(maxPt.x, P.x);
		}
	}

	//
	// Derive scene bounding sphere from bounding box.
	//
	mSceneBounds.Center = XMFLOAT3(
		0.5f*(minPt.x + maxPt.x),
		0.5f*(minPt.y + maxPt.y),
		0.5f*(minPt.z + maxPt.z));

	XMFLOAT3 extent(
		0.5f*(maxPt.x - minPt.x),
		0.5f*(maxPt.y - minPt.y),
		0.5f*(maxPt.z - minPt.z));

	mSceneBounds.Radius = sqrtf(extent.x*extent.x + extent.y*extent.y + extent.z*extent.z);

	return true;
}
Пример #10
0
void srs_env_model::CMap2DPlugin::newMapDataCB(SMapWithParameters & par)
{
	m_data->header.frame_id = m_map2DFrameId;
	m_data->header.stamp = par.currentTime;
	m_data->info.resolution = par.resolution;

	m_ocFrameId = par.frameId;
	ros::Time timestamp( par.currentTime );

	tf::StampedTransform ocToMap2DTf;

	m_bConvert = m_ocFrameId != m_map2DFrameId;

	// Get transform
	try {
		// Transformation - to, from, time, waiting time
		m_tfListener.waitForTransform(m_map2DFrameId, m_ocFrameId,
				timestamp, ros::Duration(5));

		m_tfListener.lookupTransform(m_map2DFrameId, m_ocFrameId,
				timestamp, ocToMap2DTf);

	} catch (tf::TransformException& ex) {
		ROS_ERROR_STREAM("Transform error: " << ex.what() << ", quitting callback");
		PERROR( "Transform error.");
		return;
	}


	Eigen::Matrix4f ocToMap2DTM;

	// Get transformation matrix
	pcl_ros::transformAsMatrix(ocToMap2DTf, ocToMap2DTM);

	const tButServerOcMap &map(*par.map);

	// Disassemble translation and rotation
	m_ocToMap2DRot  = ocToMap2DTM.block<3, 3> (0, 0);
	m_ocToMap2DTrans = ocToMap2DTM.block<3, 1> (0, 3);

	double minX, minY, minZ, maxX, maxY, maxZ;
	map.getTree().getMetricMin(minX, minY, minZ);
	map.getTree().getMetricMax(maxX, maxY, maxZ);

	octomap::point3d minPt(minX, minY, minZ);
	octomap::point3d maxPt(maxX, maxY, maxZ);

	octomap::OcTreeKey minKey, maxKey, curKey;

	// Try to create key
	if (!map.getTree().genKey(minPt, minKey)) {
		ROS_ERROR("Could not create min OcTree key at %f %f %f", minPt.x(), minPt.y(), minPt.z());
		return;
	}

	if (!map.getTree().genKey(maxPt, maxKey)) {
		ROS_ERROR("Could not create max OcTree key at %f %f %f", maxPt.x(), maxPt.y(), maxPt.z());
		return;
	}

	ROS_DEBUG("MinKey: %d %d %d / MaxKey: %d %d %d", minKey[0], minKey[1], minKey[2], maxKey[0], maxKey[1], maxKey[2]);

	// add padding if requested (= new min/maxPts in x&y):
	double halfPaddedX = 0.5 * m_minSizeX;
	double halfPaddedY = 0.5 * m_minSizeY;

	minX = std::min(minX, -halfPaddedX);
	maxX = std::max(maxX, halfPaddedX);

	minY = std::min(minY, -halfPaddedY);
	maxY = std::max(maxY, halfPaddedY);

	minPt = octomap::point3d(minX, minY, minZ);
	maxPt = octomap::point3d(maxX, maxY, maxZ);

	octomap::OcTreeKey paddedMaxKey;

	if (!map.getTree().genKey(minPt, m_paddedMinKey)) {
		ROS_ERROR("Could not create padded min OcTree key at %f %f %f", minPt.x(), minPt.y(), minPt.z());
		return;
	}

	if (!map.getTree().genKey(maxPt, paddedMaxKey)) {
		ROS_ERROR("Could not create padded max OcTree key at %f %f %f", maxPt.x(), maxPt.y(), maxPt.z());
		return;
	}

	ROS_DEBUG("Padded MinKey: %d %d %d / padded MaxKey: %d %d %d", m_paddedMinKey[0], m_paddedMinKey[1],
			m_paddedMinKey[2], paddedMaxKey[0], paddedMaxKey[1], paddedMaxKey[2]);

	assert(paddedMaxKey[0] >= maxKey[0] && paddedMaxKey[1] >= maxKey[1]);

	m_data->info.width = paddedMaxKey[0] - m_paddedMinKey[0] + 1;
	m_data->info.height = paddedMaxKey[1] - m_paddedMinKey[1] + 1;

	int mapOriginX = minKey[0] - m_paddedMinKey[0];
	int mapOriginY = minKey[1] - m_paddedMinKey[1];

	assert(mapOriginX >= 0 && mapOriginY >= 0);

	// might not exactly be min / max of octree:
	octomap::point3d origin;
	map.getTree().genCoords(m_paddedMinKey, par.treeDepth, origin);

	m_data->info.origin.position.x = origin.x() - par.resolution* 0.5;
	m_data->info.origin.position.y = origin.y() - par.resolution * 0.5;

	// Allocate space to hold the data (init to unknown)
	m_data->data.resize(m_data->info.width * m_data->info.height, -1);

	tButServerOcTree & tree( par.map->getTree() );
	srs_env_model::tButServerOcTree::leaf_iterator it, itEnd( tree.end_leafs() );

	// Crawl through nodes
	for ( it = tree.begin_leafs(m_crawlDepth); it != itEnd; ++it)
	{
		// Node is occupied?
		if (tree.isNodeOccupied(*it))
		{
			handleOccupiedNode(it, par);
		}// Node is occupied?
		else
		{
			handleFreeNode( it, par );
		}

	} // Iterate through octree

	invalidate();
}
Пример #11
0
void Bvh::build(std::list<IModel*> &modelList)
{
    DWORD dwBuildTime = EncoreGetTime();

    primList.clear();
   
    // destory the old information regardless
    deleteTree();
    rightBOX.reserve(maxReserve);
    
    Point3 minPt(POS_INF, POS_INF,POS_INF);
    Point3 maxPt(-POS_INF,-POS_INF,-POS_INF);
    myTriSize = 0;

    std::list<IModel*>::iterator model;
    std::list<IPrimitive*>::iterator p;

    for( model = modelList.begin(); model != modelList.end(); model++ )
    {
        myTriSize += (*model)->GetPrimitiveCount();

        // update uniform grids min and max values;
        minPt.X() = min((*model)->MinPoint().X(), minPt.X());
        minPt.Y() = min((*model)->MinPoint().Y(), minPt.Y());
        minPt.Z() = min((*model)->MinPoint().Z(), minPt.Z());

        maxPt.X() = max((*model)->MaxPoint().X(), maxPt.X());
        maxPt.Y() = max((*model)->MaxPoint().Y(), maxPt.Y());
        maxPt.Z() = max((*model)->MaxPoint().Z(), maxPt.Z());

        std::list<IPrimitive*>* pl = &(*model)->getPrimitiveList();
        for ( p = pl->begin(); p != pl->end(); p++ )
        {
            primList.push_back( (*p) );
        }
    }

    myBound = AABB( minPt, maxPt );
    
    // bvh size is always 2n-1
    maxSize = 2*myTriSize-1;
    bTree = new bvhNode[maxSize];//(bvhNode*)malloc((maxSize)*sizeof(bvhNode));
    if(bTree == NULL)
    {
        printf("no memory to make bvh\n");
        return;
    }
    try {
        leftBOX = new IPrimitive*[myTriSize]; }
    catch(std::bad_alloc&) {
        printf("no memory"); return; }
        
    m_NodeUsed = 1;
    
    construct(0, 1, myTriSize, myBound, 0, 0);
    
    // clear junk
    //if(leftBOX)
    //    free(leftBOX);   
    //leftBOX = 0;
    //rightBOX.clear();
    maxReserve = rightBOX.size();

    dwBuildTime = EncoreGetTime() - dwBuildTime;
}
void LevelBuilder::CreateBoundingBox()
{


    //
    // Compute scene bounding box.
    //
    XMFLOAT3 minPt(+MathHelper::Infinity, +MathHelper::Infinity, +MathHelper::Infinity);
    XMFLOAT3 maxPt(-MathHelper::Infinity, -MathHelper::Infinity, -MathHelper::Infinity);



    for (UINT i = 0; i < mLevelPartsInstances.size(); ++i)
    {
        minPt.x = 0.0f;
        minPt.y = 0.0f;
        minPt.z = 0.0f;

        maxPt.x = 0.0f;
        maxPt.y = 0.0f;
        maxPt.z = 0.0f;

        for (UINT j = 0; j < mLevelPartsInstances[i].Model->BasicVertices.size(); ++j)
        {

            XMFLOAT3 P = mLevelPartsInstances[i].Model->BasicVertices[j].Pos;




            minPt.x = MathHelper::Min(minPt.x, P.x);
            minPt.y = MathHelper::Min(minPt.y, P.y);
            minPt.z = MathHelper::Min(minPt.z, P.z);

            maxPt.x = MathHelper::Max(maxPt.x, P.x);
            maxPt.y = MathHelper::Max(maxPt.y, P.y);
            maxPt.z = MathHelper::Max(maxPt.z, P.z);


        }

        XMMATRIX temp = XMLoadFloat4x4(&mLevelPartsInstances[i].World);

        LevelPartsclass[i]->setWorld(mLevelPartsInstances[i].World);

        XMVECTOR Scale;
        XMVECTOR Position;
        XMVECTOR Rotation;


        XMMatrixDecompose(&Scale, &Rotation, &Position, temp);

        XMFLOAT3 tempPos;
        XMStoreFloat3(&tempPos, Position);

        LevelCollisions[i].Center = tempPos;


        LevelCollisions[i].Extents = XMFLOAT3(0.5f*(maxPt.x - minPt.x),
                                              0.5f*(maxPt.y - minPt.y),
                                              0.5f*(maxPt.z - minPt.z));

        LevelCollisions[i].collisionType = LevelPartsclass[i]->getCollisionType();

        // sets the scale of the collision box
        int scale = LevelPartsclass[i]->getScale();

        LevelCollisions[i].Extents.x = LevelCollisions[i].Extents.x * scale;
        LevelCollisions[i].Extents.y = LevelCollisions[i].Extents.y * scale;
        LevelCollisions[i].Extents.z = LevelCollisions[i].Extents.z * scale;

        if (LevelPartsclass[i]->getRotationY() != 0)
        {
            FLOAT tempX = LevelCollisions[i].Extents.x;
            FLOAT tempZ = LevelCollisions[i].Extents.z;

            LevelCollisions[i].Extents.x = tempZ;
            LevelCollisions[i].Extents.z = tempX;

        }


        //// this doesn't work, useless atm
        //LevelPartsBox[i]->setCollisionType();


        LevelPartsclass[i]->setAABB(&LevelCollisions[i]);

    }
}
Пример #13
0
bool Projekt::Init()
{
	if (!D3D11App::Init())
		return false;

	// Initialize effects, input layouts and texture manager
	Effects::InitAll(mDirect3D->GetDevice());
	InputLayouts::InitAll(mDirect3D->GetDevice());
	mTextureMgr.init(mDirect3D->GetDevice());

	// Initialize wireframe render state
	D3D11_RASTERIZER_DESC wireFrameDesc;
	ZeroMemory(&wireFrameDesc, sizeof(D3D11_RASTERIZER_DESC));
	wireFrameDesc.FillMode = D3D11_FILL_WIREFRAME;
	wireFrameDesc.CullMode = D3D11_CULL_BACK;
	wireFrameDesc.FrontCounterClockwise = false;
	wireFrameDesc.DepthClipEnable = true;

	HR(mDirect3D->GetDevice()->CreateRasterizerState(&wireFrameDesc, &WireFrameRS));

	//--------------------------------------------------------
	// Create sky
	//--------------------------------------------------------
	mSky = new Sky(mDirect3D->GetDevice(), L"Data/Textures/snowcube1024.dds", 5000.0f);

	//--------------------------------------------------------
	// Create terrain
	//--------------------------------------------------------
	// Describe terrain
	Terrain::InitInfo tInitInfo;
	tInitInfo.HeightMapFilename = L"Data/Textures/Heightmaps/terrain.raw";
	tInitInfo.LayerMapFilename0 = L"Data/Textures/grass.dds";
	tInitInfo.LayerMapFilename1 = L"Data/Textures/darkdirt.dds";
	tInitInfo.LayerMapFilename2 = L"Data/Textures/stone.dds";
	tInitInfo.LayerMapFilename3 = L"Data/Textures/lightdirt.dds";
	tInitInfo.LayerMapFilename4 = L"Data/Textures/snow.dds";
	tInitInfo.BlendMapFilename = L"Data/Textures/blend.dds";
	tInitInfo.HeightScale = 50.0f;
	tInitInfo.HeightmapWidth = 2049;
	tInitInfo.HeightmapHeight = 2049;
	tInitInfo.CellSpacing = 0.5f;

	// Initialize terrain
	mTerrain.Init(mDirect3D->GetDevice(), mDirect3D->GetImmediateContext(), tInitInfo);

	//--------------------------------------------------------
	// Particle systems
	//--------------------------------------------------------
	mRandomTexSRV = d3dHelper::CreateRandomTexture1DSRV(mDirect3D->GetDevice());

	std::vector<std::wstring> flares;
	flares.push_back(L"Data\\Textures\\flare0.dds");
	mFlareTexSRV = d3dHelper::CreateTexture2DArraySRV(mDirect3D->GetDevice(), mDirect3D->GetImmediateContext(), flares);

	mFire.init(mDirect3D->GetDevice(), Effects::FireFX, mFlareTexSRV, mRandomTexSRV, 500);
	mFire.setEmitPos(XMFLOAT3(65.0f, 5.0f, 0.0f));

	//--------------------------------------------------------
	// Create shadow map
	//--------------------------------------------------------
	mShadowMapSize = 2048;
	mShadowMap = new ShadowMap(mDirect3D->GetDevice(), mShadowMapSize, mShadowMapSize);

	//--------------------------------------------------------
	// Load models
	//--------------------------------------------------------
	mGenericModel = new GenericModel(mDirect3D->GetDevice(), mTextureMgr, "Data\\Models\\Collada\\duck.dae", L"Data\\Models\\Collada\\");

	//mSkinnedModel = new GenericSkinnedModel(mDirect3D->GetDevice(), mTextureMgr, "Data\\Models\\Collada\\AnimTest\\test_Collada_DAE.dae", L"Data\\Models\\Collada\\AnimTest\\");

	mPlayerModel = new GenericModel(mDirect3D->GetDevice(), mTextureMgr, "Data\\Models\\OBJ\\Cop\\cop.obj", L"Data\\Models\\OBJ\\Cop\\");

	Player::InitProperties playerProp;

	playerProp.PlayerID = 0;
	playerProp.Nickname = "Hyzor";
	playerProp.Speed = 1.0f;
	playerProp.Health = 1.0f;
	playerProp.Position = XMFLOAT3(0.0f, 0.0f, 0.0f);
	playerProp.Scale = XMFLOAT3(1.0f, 1.0f, 1.0f);
	playerProp.Angle = 0.0f;
	playerProp.Model = mPlayerModel;

	mPlayer.Init(playerProp);
	
	//--------------------------------------------------------
	// Create model instances
	//--------------------------------------------------------

	GenericModelInstance genericInstance;
	genericInstance.model = mGenericModel;

// 	GenericSkinnedModelInstance genSkinnedInstance;
// 	genSkinnedInstance.model = mSkinnedModel;
// 	genSkinnedInstance.FinalTransforms.resize(mSkinnedModel->skinnedData.getBoneCount());
// 	genSkinnedInstance.ClipName = "animation";
// 	genSkinnedInstance.TimePos = 0.0f;

	//--------------------------------------------------------
	// Scale, rotate and move model instances
	//--------------------------------------------------------
	XMMATRIX modelScale = XMMatrixScaling(1.0f, 1.0f, 1.0f);
	XMMATRIX modelRot = XMMatrixRotationY(0.0f);
	XMMATRIX modelOffset = XMMatrixTranslation(0.0f, 0.0f, 0.0f);

	//modelScale = XMMatrixScaling(0.1f, 0.1f, 0.1f);
	modelOffset = XMMatrixTranslation(-30.0f, 15.0f, -110.0f);
	XMStoreFloat4x4(&genericInstance.world, modelScale*modelRot*modelOffset);

// 	modelOffset = XMMatrixTranslation(50.0f, 15.0f, -110.0f);
// 	XMStoreFloat4x4(&genSkinnedInstance.world, modelScale*modelRot*modelOffset);

	//--------------------------------------------------------
	// Insert model instances to the vector
	//--------------------------------------------------------
	mGenericInstances.push_back(genericInstance);

/*	mGenSkinnedInstances.push_back(genSkinnedInstance);*/

	//--------------------------------------------------------
	// Compute scene bounding box
	//--------------------------------------------------------
	XMFLOAT3 minPt(+MathHelper::infinity, +MathHelper::infinity, +MathHelper::infinity);
	XMFLOAT3 maxPt(-MathHelper::infinity, -MathHelper::infinity, -MathHelper::infinity);

	// Get vertex positions from all models
	for (UINT i = 0; i < mGenericInstances.size(); ++i)
	{
		for (UINT j = 0; j < mGenericInstances[i].model->vertices.size(); ++j)
		{
			XMFLOAT3 vPos = mGenericInstances[i].model->vertices[j]->position;

			minPt.x = MathHelper::getMin(minPt.x, vPos.x);
			minPt.y = MathHelper::getMin(minPt.x, vPos.x);
			minPt.z = MathHelper::getMin(minPt.x, vPos.x);

			maxPt.x = MathHelper::getMax(maxPt.x, vPos.x);
			maxPt.y = MathHelper::getMax(maxPt.x, vPos.x);
			maxPt.z = MathHelper::getMax(maxPt.x, vPos.x);
		}
	}

	// Get vertex positions from all skinned models
// 	for (UINT i = 0; i < mGenSkinnedInstances.size(); ++i)
// 	{
// 		for (UINT j = 0; j < mGenSkinnedInstances[i].model->vertices.size(); ++j)
// 		{
// 			XMFLOAT3 vPos = mGenSkinnedInstances[i].model->vertices[j]->position;
// 
// 			minPt.x = MathHelper::getMin(minPt.x, vPos.x);
// 			minPt.y = MathHelper::getMin(minPt.x, vPos.x);
// 			minPt.z = MathHelper::getMin(minPt.x, vPos.x);
// 
// 			maxPt.x = MathHelper::getMax(maxPt.x, vPos.x);
// 			maxPt.y = MathHelper::getMax(maxPt.x, vPos.x);
// 			maxPt.z = MathHelper::getMax(maxPt.x, vPos.x);
// 		}
// 	}

	// Now continue with terrain vertex positions
	for (UINT i = 0; i < mTerrain.getPatchVertices().size(); ++i)
	{
		XMFLOAT3 vPos = mTerrain.getPatchVertices()[i].position;

		minPt.x = MathHelper::getMin(minPt.x, vPos.x);
		minPt.y = MathHelper::getMin(minPt.x, vPos.x);
		minPt.z = MathHelper::getMin(minPt.x, vPos.x);

		maxPt.x = MathHelper::getMax(maxPt.x, vPos.x);
		maxPt.y = MathHelper::getMax(maxPt.x, vPos.x);
		maxPt.z = MathHelper::getMax(maxPt.x, vPos.x);
	}

	// Sphere center is at half of these new dimensions
	mSceneBounds.Center = XMFLOAT3(	0.5f*(minPt.x + maxPt.x),
		0.5f*(minPt.y + maxPt.y),
		0.5f*(minPt.z + maxPt.z));

	// Calculate the sphere radius
	XMFLOAT3 extent(0.5f*(maxPt.x - minPt.x),
		0.5f*(maxPt.y - minPt.y),
		0.5f*(maxPt.z - minPt.z));

	mSceneBounds.Radius = sqrtf(extent.x*extent.x + extent.y*extent.y + extent.z*extent.z);

	OnResize();

	return true;
}
// ######################################################################
Image<float> ContourBoundaryDetector::getContourBoundaryEdgels()
{
  // NOTE: FIXXXX: TENSOR-VOTING IS PROBABLY A BETTER IDEA

  int w = itsImage.getWidth();
  int h = itsImage.getHeight();
  Image<float> edgelBoundaryImage(w,h,ZEROS);

  int step  = BOUNDARY_STEP_SIZE;
  int hstep = step/2;
  //int wSize = BOUNDARY_STEP_SIZE+1;

  // set up the center and surround opponency locations
  std::vector<std::vector<Point2D<int> > > cCoords(NUM_RIDGE_DIRECTIONS);
  std::vector<std::vector<Point2D<int> > > sCoords(NUM_RIDGE_DIRECTIONS);
  std::vector<float> angles;

  for(uint k = 0; k < NUM_RIDGE_DIRECTIONS; k++)
    {
      cCoords[k] = std::vector<Point2D<int> >();  
      sCoords[k] = std::vector<Point2D<int> >();  

      angles.push_back(k*2.0*M_PI/float(NUM_RIDGE_DIRECTIONS));
    }

  // fill the center coordinates
  for(int i = -step/2; i < step/2; i++)
    {
      cCoords[0].push_back(Point2D<int>( i, 0));
      cCoords[1].push_back(Point2D<int>( i, i));
      cCoords[2].push_back(Point2D<int>( 0, i));
      cCoords[3].push_back(Point2D<int>( i,-i));
    }

  // fill the surround coordinates (bottom or right)
  for(int i = 0; i < hstep; i++)
    {
      sCoords[0].push_back(Point2D<int>( i+hstep,       0));
      sCoords[0].push_back(Point2D<int>( i+hstep,   hstep));
      sCoords[0].push_back(Point2D<int>( i+hstep,  -hstep));

      sCoords[1].push_back(Point2D<int>( i+hstep, i+hstep));
      sCoords[1].push_back(Point2D<int>( i+step , i      ));
      sCoords[1].push_back(Point2D<int>( i      ,-i-step ));

      sCoords[2].push_back(Point2D<int>(       0, i+hstep));
      sCoords[2].push_back(Point2D<int>(   hstep, i+hstep));
      sCoords[2].push_back(Point2D<int>(  -hstep, i+hstep));

      sCoords[3].push_back(Point2D<int>( i+hstep,-i-hstep));
      sCoords[3].push_back(Point2D<int>( i      ,-i-step ));
      sCoords[3].push_back(Point2D<int>( i+step ,-i      ));
    }

  // fill the surround coordinates (top or left)
  for(int i = -hstep; i < 0; i++)
    {
      sCoords[0].push_back(Point2D<int>( i-hstep,       0));
      sCoords[0].push_back(Point2D<int>( i-hstep,   hstep));
      sCoords[0].push_back(Point2D<int>( i-hstep,  -hstep));

      sCoords[1].push_back(Point2D<int>( i-hstep, i-hstep));
      sCoords[1].push_back(Point2D<int>( i-step , i      ));
      sCoords[1].push_back(Point2D<int>( i      , i-step ));

      sCoords[2].push_back(Point2D<int>(       0, i-hstep));
      sCoords[2].push_back(Point2D<int>(   hstep, i-hstep));
      sCoords[2].push_back(Point2D<int>(  -hstep, i-hstep));

      sCoords[3].push_back(Point2D<int>( i-hstep,-i+hstep));
      sCoords[3].push_back(Point2D<int>( i      ,-i+step ));
      sCoords[3].push_back(Point2D<int>( i-step ,-i      ));
    }

  // reset the edgel storage
  // NOTE: we will keep edgel at index 0 empty
  int wEdgel = (w+hstep)/step; 
  int hEdgel = (h+hstep)/step;
  itsCompleteEdgels = 
    Image<std::vector<rutz::shared_ptr<Edgel> > >(wEdgel, hEdgel, ZEROS);
  itsEdgels = Image<rutz::shared_ptr<Edgel> >(wEdgel, hEdgel, ZEROS);

  // go through each point
  // with the specified step size
  int wLimit = (w/step)*step;
  int hLimit = (h/step)*step;
  for(int j = step; j < hLimit; j+= step)
    {
      for(int i = step; i < wLimit; i+= step)
        {
	  Point2D<int> cpt(i,j);
	  
	  int maxk = -1;
	  Point2D<int> maxPt(-1,-1);
	  float maxVal = -1.0F;

          uint iEdgel = i/step;
          uint jEdgel = j/step;

	  // for each direction
	  for(uint k = 0; k < NUM_RIDGE_DIRECTIONS; k++)
	    {
	      Point2D<int> maxCKpt(-1,-1);
	      float maxCKval = 0.0;

	      // get maximum contour value for the center size
	      // to make the contour detector phase invariant
	      for(uint ci = 0; ci < cCoords[k].size(); ci++)
		{
		  Point2D<int> pt = cCoords[k][ci] + cpt;  
		  if(edgelBoundaryImage.coordsOk(pt)) 
		    {
		      float val = itsRidgeDirectionNMS[k].getVal(pt); 
		      if(maxCKval < val) 
			{
			  maxCKval = val; maxCKpt = pt;
			}
		    }
		}

	      float maxSKval = 0.0;

	      // get the maximum value for the surround 
	      for(uint si = 0; si < sCoords[k].size(); si++)
		{
		  Point2D<int> pt = sCoords[k][si] + cpt;  
		  if(edgelBoundaryImage.coordsOk(pt)) 
		    {
		      float val = itsRidgeDirectionNMS[k].getVal(pt); 
		      if(maxSKval < val) maxSKval = val;
		    }
		}
	      
	      // if center > 0 and wins
	      if(maxCKval > 0.0F && maxCKval > maxSKval)
		{
		  if(maxCKval > maxVal) 
		    {
		      maxPt  = maxCKpt;
		      maxVal = maxCKval;
		      maxk   = k;
		    }
                  
                  // put the new edgel in the right position
                  rutz::shared_ptr<Edgel> 
                    edgel(new Edgel(maxCKpt, angles[k], k, maxCKval)); 
                  
                  std::vector<rutz::shared_ptr<Edgel> >
                    cEdgelList = itsCompleteEdgels.getVal(iEdgel,jEdgel);

                  uint eNum = cEdgelList.size();
                  uint place = 0;
                  for(uint ce = 0; ce < eNum; ce++)
                    {
                      if(cEdgelList[ce]->val < maxCKval)
                        {
                          place = ce; ce = eNum;
                        }
                      else place = ce+1;
                    }
                  //LINFO("place: %d  | eNum: %d", place, eNum);
                  
                  cEdgelList.push_back(edgel);
                  
                  // for(uint ce = 0; ce < cEdgelList.size(); ce++)
                  //   LINFO("%12.5f %3d", cEdgelList[ce]->val,  
                  //         cEdgelList[ce]->angleIndex);

                  if(place != eNum)
                    {
                      // LINFO("move one");
                  
                      for(int ce = int(eNum-1); ce >= int(place); ce--)
                        {
                          cEdgelList[ce+1] = cEdgelList[ce];
                        }
                      
                      // for(uint ce = 0; ce < cEdgelList.size(); ce++)
                      //   LINFO("%12.5f %3d", cEdgelList[ce]->val,  
                      //         cEdgelList[ce]->angleIndex);
                      
                      cEdgelList[place] = edgel;                  
                      
                      // LINFO("place the new one properly");

                      // for(uint ce = 0; ce < cEdgelList.size(); ce++)
                      //   LINFO("%12.5f %3d", cEdgelList[ce]->val,  
                      //         cEdgelList[ce]->angleIndex);
                    }
                  // else LINFO("last place");

                  itsCompleteEdgels.setVal(iEdgel,jEdgel, cEdgelList);


                  // LINFO("%d %d: size: %d ", i,j, 
                  //       int(itsCompleteEdgels.getVal(iEdgel,jEdgel).size()));

                  // for(uint ce = 0; ce < cEdgelList.size(); ce++)
                  //   LINFO("%12.5f %3d", cEdgelList[ce]->val,  
                  //         cEdgelList[ce]->angleIndex);
		}
	    }

	  // if there is a winner
	  if(maxk != -1)
	    {
              itsEdgels.setVal
                (iEdgel,jEdgel, itsCompleteEdgels.getVal(iEdgel,jEdgel)[0]);

	      float borderK = 
		fmod((maxk+(NUM_RIDGE_DIRECTIONS/2)),NUM_RIDGE_DIRECTIONS);

	      float dx = cos(borderK * M_PI/4.0) * hstep; 
	      float dy = sin(borderK * M_PI/4.0) * hstep;

	      Point2D<int> pt = maxPt;
	      Point2D<int> p1 = pt + Point2D<int>( dx+.5,  dy+.5); 
	      Point2D<int> p2 = pt + Point2D<int>(-dx-.5, -dy-.5);

              //uint iEdgel = i/step;
              //uint jEdgel = j/step;
              //if(iEdgel >= 10 && iEdgel <= 25 && jEdgel >= 1 && jEdgel <= 14)
              //   {
              //     LINFO("maxk: %d -> %d  -> %f  %f (%f %f %f %f)  |%f %f", 
              //           maxk, (maxk+(NUM_RIDGE_DIRECTIONS/2)), 
              //           (borderK*M_PI)/float(NUM_RIDGE_DIRECTIONS), borderK, 
              //           cos(0), cos(M_PI/4.0), cos(M_PI/2.0), cos(M_PI*.75),
              //           dx, dy);
	      


              //LINFO("%d %d | %d %d | %d %d::::: %d %d  %d", 
              //         pt.i, pt.j, p1.i, p1.j, p2.i, p2.j, iEdgel, jEdgel, maxk);
                  
              // draw the straightline contour in the image 
              // for visualization
              drawLine(edgelBoundaryImage, p1, p2, 255.0F);
              //drawDisk(edgelBoundaryImage, pt, 2,  255.0F);
              // }      
              
	    }
	}
    }

  return edgelBoundaryImage;
}