Ejemplo n.º 1
0
static COMMAND_FUNC( do_find_face )
{
	OpenCV_Image *src;
	OpenCV_Cascade *casc_p;
	CvPoint2D32f* features;
	int frame_number;

	src = PICK_OCVI("input OpenCV image");
	casc_p = PICK_CASCADE("classifier cascade");
	frame_number = HOW_MANY("frame number");

	if( src == NO_OPENCV_IMAGE || casc_p == NO_CASCADE ) return;

	if( storage == NULL )
		storage = cvCreateMemStorage(0); // what is the arg here?

	features = FindFace(QSP_ARG  src->ocv_image, storage, casc_p->ocv_cascade, frame_number);
	//cvReleaseImage(&src->ocv_image);
	/* BUG need to do something with the feature array */
	if( features == NULL )
		WARN("find_face:  Null feature array!?");

	// Deallocate memory.
	cvReleaseMemStorage(&storage);
}
Ejemplo n.º 2
0
float
AreaSurfaceMesh::GetPointHeight(
	__in const NWN::Vector2 & pt
	) const
/*++

Routine Description:

	This routine computes the height at a particular point.

Arguments:

	pt - Supplies the point to compute the height for.

Return Value:

	Returns the height, or 0.0f if the coordinates were invalid.

Environment:

	User mode.

--*/
{
	const SurfaceMeshFace * Face;

	Face = FindFace( pt );

	if (Face == NULL)
		return 0.0f;

	return (float) Math::PlaneHeightAtPoint( Face->Normal, Face->D, pt );
}
Ejemplo n.º 3
0
//-----------------------------------------------------------------------------
// Purpose: Deselects the given face.
//-----------------------------------------------------------------------------
void CToolPickFace::DeselectFace(CMapFace *pFace)
{
	int nIndex = FindFace(pFace);
	if (nIndex != -1)
	{
		DeselectFace(nIndex);
	}
}
Ejemplo n.º 4
0
/**
 * Given a geographic coordinate (lon, lat), find the corresponding
 * face, subface, and UVW coordinates on surface of the icosahedron.
 */
void DymaxIcosa::FindFaceUV(const DPoint2 &p, int &face, int &subface,
							DPoint3 &uvw)
{
	DPoint3 p3;

	geo_to_xyz(p, p3);
	FindFace(p3, face, subface);
	FindUV(p3, face, uvw);
}
Ejemplo n.º 5
0
/**
 * Given a geographic coordinate (lon, lat), find the corresponding
 * point on the surface of the icosahedron.
 */
void DymaxIcosa::GeoToFacePoint(const DPoint2 &p, int &face, int &subface,
							 DPoint3 &p_out)
{
	DPoint3 p3, uvw;

	geo_to_xyz(p, p3);
	FindFace(p3, face, subface);
	FindUV(p3, face, uvw);

	p_out = m_face[face].base +
		   (m_face[face].vec_a * uvw.x) +
		   (m_face[face].vec_b * uvw.y);
}
Ejemplo n.º 6
0
//-----------------------------------------------------------------------------
// Purpose: Selects the face unconditionally.
// Input  : pFace - face to select.
//-----------------------------------------------------------------------------
void CToolPickFace::SelectFace(CMapFace *pFace)
{
	int nIndex = FindFace(pFace);
	if (nIndex != -1)
	{
		//
		// The face is in our list, update its selection state.
		//
		m_Faces[nIndex].eState = FaceState_Select;
		pFace->SetSelectionState(SELECT_NORMAL);
	}
	else
	{
		//
		// The face is not in our list, add it.
		//
		AddToList(pFace, FaceState_Select);
		pFace->SetSelectionState(SELECT_NORMAL);
	}
}
Ejemplo n.º 7
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : pFace - 
//-----------------------------------------------------------------------------
void CToolPickFace::CycleSelectFace(CMapFace *pFace)
{
	int nIndex = FindFace(pFace);
	if (nIndex != -1)
	{
		//
		// The face is in our list, update its selection state.
		//
		if (m_Faces[nIndex].eState == FaceState_Partial)
		{
			DeselectFace(nIndex);
		}
		else if (m_Faces[nIndex].eState == FaceState_Select)
		{
			if (m_Faces[nIndex].eOriginalState == FaceState_Partial)
			{
				m_Faces[nIndex].eState = FaceState_Partial;
				pFace->SetSelectionState(SELECT_MULTI_PARTIAL);
			}
			else
			{
				DeselectFace(nIndex);
			}
		}
		else if (m_Faces[nIndex].eState == FaceState_None)
		{
			m_Faces[nIndex].eState = FaceState_Select;
			pFace->SetSelectionState(SELECT_NORMAL);
		}
	}
	else
	{
		//
		// The face is not in our list, add it.
		//
		AddToList(pFace, FaceState_Select);
		pFace->SetSelectionState(SELECT_NORMAL);
	}
}
Ejemplo n.º 8
0
/**
 * Given a geographic coordinate (lon, lat), find the corresponding
 * dymaxion map coordinate, on the classic flattened dymaxion map.
 * The output is unit-edge triangles, which means the whole output
 * extents are x [0, 5.5] and y [0, 2.6].
 */
bool DymaxIcosa::GeoToDymax(const DPoint2 &geo, DPoint2 &dymax)
{
	DPoint3 p3, uvw;
	int face, subface;

	geo_to_xyz(geo, p3);
	FindFace(p3, face, subface);
	FindUV(p3, face, uvw);

	DPoint2 uv(uvw.x, uvw.y);
	//assert(uv.x <= 1 && uv.y <= 1);

	// Not exactly sure why we need to do this - apparently the UV are
	//  assuming a unit-radius, rather than unit-edge icosahedron
	uv /= m_edge_length;

	int a, b, c;
	switch (face)
	{
	case 0:
		a = 17; b = 22; c = 16; break;
	case 1:
		a = 17; b = 16; c = 10; break;
	case 2:
		a = 17; b = 10; c = 11; break;
	case 3:
		a = 17; b = 11; c = 18; break;
	case 4:
		a = 17; b = 23; c = 22; break;
	case 5:
		a = 21; b = 16; c = 22; break;
	case 6:
		a = 16; b = 15; c = 9; break;
	case 7:
		a = 9; b = 10; c = 16; break;
	case 8:
		if (subface == 4 || subface == 5)
			{ a = 10; b = 1; c = 2; }
		else
			{ a = 10; b = 9; c = 1; }
		break;
	case 9:
		a = 2; b = 11; c = 10; break;
	case 10:
		a = 11; b = 3; c = 12; break;
	case 11:
		a = 12; b = 18; c = 11; break;
	case 12:
		a = 18; b = 12; c = 19; break;
	case 13:
		a = 19; b = 24; c = 18; break;
	case 14:
		a = 25; b = 19; c = 20; break;
	case 15:
		if (subface == 0 || subface == 4 || subface == 5)
			{ a = 13; b = 26; c = 20; }
		else
			{ a = 0; b = 9; c = 8; }
		break;
	case 16:
		a = 0; b = 1; c = 9; break;
	case 17:
		a = 4; b = 12; c = 3; break;
	case 18:
		a = 13; b = 19; c = 12; break;
	case 19:
		a = 13; b = 20; c = 19; break;
	default:
		return false;
	}
	DPoint2 base = m_flatverts[a];
	DPoint2 vec1 = m_flatverts[b] - base;
	DPoint2 vec2 = m_flatverts[c] - base;

	dymax = base + (vec1 * uv.x) + (vec2 * uv.y);
	return true;
}
Ejemplo n.º 9
0
//-----------------------------------------------------------------------------
// Purpose: Handles the left mouse button up message in the 3D view.
// Input  : pView - The view that the event occurred in.
//			nFlags - Flags per the Windows mouse message.
//			point - Point in client coordinates where the event occurred.
// Output : Returns true if the message was handled by the tool, false if not.
//-----------------------------------------------------------------------------
bool CToolPickFace::OnLMouseDown3D(CMapView3D *pView, UINT nFlags, CPoint point)
{
	bool bControl = ((nFlags & MK_CONTROL) != 0);
	bool bShift = ((nFlags & MK_SHIFT) != 0);

	if (!m_bAllowMultiSelect)
	{
		// Ignore shift click for single selection mode.
		bShift = false;
	}

	unsigned long uFace;
	CMapClass *pObject = pView->NearestObjectAt(point, uFace);
	if (pObject != NULL)
	{
		CMapSolid *pSolid = dynamic_cast <CMapSolid *>(pObject);
		if (pSolid != NULL)
		{
			//
			// We clicked on a solid.
			//
			if (!bShift)
			{
				//
				// Get the face that we clicked on.
				//
				CMapFace *pFace = pSolid->GetFace(uFace);
				ASSERT(pFace != NULL);

				if (pFace != NULL)
				{
					if ((!m_bAllowMultiSelect) || (!bControl))
					{
						// Single select.
						DeselectAll();
						SelectFace(pFace);
					}
					else
					{
						// Multiselect.
						CycleSelectFace(pFace);
					}
				}
			}
			else
			{
				//
				// Holding down shift. Select or deselect all the faces on the solid.
				// Only deselect if all the faces in the solid were selected.
				//
				bool bAllSelected = true;
				int nFaceCount = pSolid->GetFaceCount();
				for (int nFace = 0; nFace < nFaceCount; nFace++)
				{
					CMapFace *pFace = pSolid->GetFace(nFace);
					int nIndex = FindFace(pFace);
					if ((nIndex == -1) || (m_Faces[nIndex].eState != FaceState_Select))
					{
						bAllSelected = false;
						break;
					}
				}

				if (!bControl)
				{
					DeselectAll();
				}

				nFaceCount = pSolid->GetFaceCount();
				for (nFace = 0; nFace < nFaceCount; nFace++)
				{
					CMapFace *pFace = pSolid->GetFace(nFace);
					if (bAllSelected)
					{
						DeselectFace(pFace);
					}
					else
					{
						SelectFace(pFace);
					}
				}
			}

			if (m_pNotifyTarget)
			{
				m_pNotifyTarget->OnNotifyPickFace(this);
			}
		}
	}

	return true;
}
Ejemplo n.º 10
0
bool
AreaSurfaceMesh::GetLineSegmentFacesAndMesh(
	__in const NWN::Vector2 & Start,
	__in const NWN::Vector2 & End,
	__in_opt const TileSurfaceMesh * ExcludeSurfaceMesh,
	__in bool Walkable,
	__out const SurfaceMeshFace * * Face1,
	__out const SurfaceMeshFace * * Face2,
	__out const TileSurfaceMesh * * SurfaceMesh
	) const
/*++

Routine Description:

	Given the start and end bounding points of a line segment, which must
	reside entirely within the same tile surface mesh (although it may reside
	upon a seam), this routine returns the walk mesh faces that contain the
	start and end points, respectively.  Both faces are guaranteed to be joined
	to the same tile surface mesh, which is also returned.

	Only walkable faces are returned.

Arguments:

	Start - Supplies the first point of the line segment.  The line segment
	        must reside entirely within one tile surface mesh.

	End - Supplies the second point of the line segment.  The line segment must
	      reside entirely within one tile surface mesh.

	ExcludeSurfaceMesh - Optionally supplies a surface mesh to exclude if there
	                     should be be a tie between which surface mesh to pick
	                     for a particular triangle.  If the caller is following
	                     a line through several intersecting segments, then
	                     subsequent calls must specify the previous surface
	                     mesh in order to ensure forward progress.

	Walkable - Supplies a Boolean value indicating whether only walkable faces
	           are to be considered.

	Face1 - Receives the face containing the Start point.

	Face2 - Receives the face containing the End point.

	SurfaceMesh - Receives the tile surface mesh that both faces are joined to.

Return Value:

	Returns true two faces joined to the same tile surface mesh and containing
	the Start and End points could be located.  Otherwise, the routine returns
	false.

Environment:

	User mode.

--*/
{
	const SurfaceMeshFace * f1;
	const TileSurfaceMesh * t1;
	const SurfaceMeshFace * f2;
	const TileSurfaceMesh * t2;

	f1 = FindFace( Start, &t1 );

	if (f1 == NULL)
		return false;

	if ((Walkable) && (!(f1->Flags & SurfaceMeshFace::WALKABLE)))
		return false;

	f2 = FindFace( End, &t2 );

	if (f2 == NULL)
		return false;

	if ((Walkable) && (!(f2->Flags & SurfaceMeshFace::WALKABLE)))
		return false;

//	WriteText( "Try (%f, %f) and (%f, %f)\n", f1->Centroid2.x, f1->Centroid2.y, f2->Centroid2.x, f2->Centroid2.y );

	//
	// If the points were not in the same surface mesh then it's possible
	// that we picked the wrong one.  This may happen as it is not very
	// well defined what the behavior should be should we be right on a
	// seam between tile surface walkmesh objects.
	//
	// In the seam case, we iterate through all neighbor edges, looking for
	// the edge that matches the line.  Once we've got the edge, we'll pick
	// the two triangles that are in the same tiele surface walkmesh.
	//

	if ((t1 != t2) || (t1 == ExcludeSurfaceMesh))
	{
		const SurfaceMeshFace * faces[ 4 ];
		const SurfaceMeshEdge * e1;
		const SurfaceMeshEdge * e2;
		NWN::Vector2            v1;
		NWN::Vector2            v2;
		NWN::Vector2            I0;
		unsigned long           TestFaceId;
		bool                    Parallel;

//		WriteText( "We weren't in the same walkmesh!\n" );

		//
		// Build a list of candidate faces.  We start with the two that we've
		// originally found, but these may be on the wrong sides -- that is,
		// they might not be on the correct tile surface walkmesh.  Check the
		// other sides (if applicable); two of the faces will be on opposite
		// walkmesh tiles (i.e. the triangle we just walked through, and the
		// triangle that we'll walk through after we pass through this next
		// walkmesh.  Conversely, two of the faces will be on the correct
		// walkmesh tile -- the next walkmesh tile up.
		//

		faces[ 0 ] = f1;
		faces[ 1 ] = NULL;
		faces[ 2 ] = f2;
		faces[ 3 ] = NULL;

		for (unsigned long i = 0; i < 3; i += 1)
		{
			e1 = &GetEdges( )[ f1->Edges[ i ] ];

			//
			// Check that the edge intersects with our line segment's overlap
			// coordinate set.
			//

			v1.x = GetPoints( )[ e1->Points1 ].x;
			v1.y = GetPoints( )[ e1->Points1 ].y;
			v2.x = GetPoints( )[ e1->Points2 ].x;
			v2.y = GetPoints( )[ e1->Points2 ].y;

			if (!Math::IntersectSegments2( Start, End, v1, v2, I0, Parallel ))
			{
				e1 = NULL;
				continue;
			}

			//
			// We want the triangle on the other edge of this face.  Try it
			// too.
			//

			if (GetFaceId( f1 ) != e1->Triangles1)
				TestFaceId = e1->Triangles1;
			else
				TestFaceId = e1->Triangles2;

			if (TestFaceId == (unsigned long) -1)
				continue;

			faces[ 1 ] = &GetTriangles( )[ TestFaceId ];

			if (!IsPointInTriangle( faces[ 1 ], Start, GetPoints( ) ))
			{
				faces[ 1 ] = NULL;
				continue;
			}

			break;
		}

		for (unsigned long i = 0; i < 3; i += 1)
		{
			e2 = &GetEdges( )[ f2->Edges[ i ] ];

			//
			// Check that the edge intersects with our line segment's overlap
			// coordinate set.
			//

			v1.x = GetPoints( )[ e2->Points1 ].x;
			v1.y = GetPoints( )[ e2->Points1 ].y;
			v2.x = GetPoints( )[ e2->Points2 ].x;
			v2.y = GetPoints( )[ e2->Points2 ].y;

			if (!Math::IntersectSegments2( Start, End, v1, v2, I0, Parallel ))
			{
				e2 = NULL;
				continue;
			}

			//
			// We want the triangle on the other edge of this face.  Try it
			// too.
			//

			if (GetFaceId( f2 ) != e2->Triangles1)
				TestFaceId = e2->Triangles1;
			else
				TestFaceId = e2->Triangles2;

			if (TestFaceId == (unsigned long) -1)
				continue;

			faces[ 3 ] = &GetTriangles( )[ TestFaceId ];

			if (!IsPointInTriangle( faces[ 3 ], End, GetPoints( )))
			{
				faces[ 3 ] = NULL;
				continue;
			}

			break;
		}

//		faces[ 0 ] = e1->Triangles1 == (unsigned long) -1 ? NULL : &GetTriangles( )[ e1->Triangles1 ];
//		faces[ 1 ] = e1->Triangles2 == (unsigned long) -1 ? NULL : &GetTriangles( )[ e1->Triangles2 ];
//		faces[ 2 ] = e2->Triangles1 == (unsigned long) -1 ? NULL : &GetTriangles( )[ e2->Triangles1 ];
//		faces[ 3 ] = e2->Triangles1 == (unsigned long) -1 ? NULL : &GetTriangles( )[ e2->Triangles2 ];

		f1 = NULL;
		f2 = NULL;

		//
		// Check each triangle/edge permutation for the two that have the
		// same tile surface mesh.  These two triangles will be the ones
		// that we're looking for.
		//

		for (unsigned long i = 0; i < 2 && f1 == NULL; i += 1)
		{
			if (faces[ i + 0 ] == NULL)
				continue;

			for (unsigned long j = 0; j < 2; j += 1)
			{
				if (faces[ j + 2 ] == NULL)
					continue;

//				if ((!IsPointInTriangle( faces[ i + 0 ], Start, GetPoints( ) )) ||
//				    (!IsPointInTriangle( faces[ j + 2 ], End, GetPoints( ) )))
//					continue;

				f1 = faces[ i + 0 ];
				f2 = faces[ j + 2 ];
				t1 = &GetTileSurfaceMesh( f1 );
				t2 = &GetTileSurfaceMesh( f2 );

//				WriteText( "Try again: (%f, %f) and (%f, %f)\n", f1->Centroid2.x, f1->Centroid2.y, f2->Centroid2.x, f2->Centroid2.y );

				if ((t1 == t2) &&
				    (t1 != ExcludeSurfaceMesh))
					break;

				f1 = NULL;
				f2 = NULL;
			}
		}

		if (f1 == NULL)
		{
//			WriteText( "No triangles sharing our edge have the same TSM???\n" );
			return false;
		}
	}

//	WriteText( "%f %f %f %f\n", f1->Centroid2.x, f1->Centroid2.y, f2->Centroid2.x, f2->Centroid2.y );

	*Face1 = f1;
	*Face2 = f2;
	*SurfaceMesh = t1;

	return true;
}