Beispiel #1
0
Graph *CreateGraph(CImage *cimg)
{
  Graph *g=NULL;
  CImage *cxyz, *clab;
  int ncols, nrows;

  ncols = cimg->C[0]->ncols;
  nrows = cimg->C[0]->nrows;

  cxyz = CImageRGBtoXYZ(cimg);
  clab = CImageXYZtoLAB(cxyz);
  DestroyCImage(&cxyz);

  g = (Graph *) calloc(1,sizeof(Graph));
  if (g != NULL) {
    g->nodes = ComputeNodes(clab);
    g->edges = ComputeEdges(clab);
    g->nnodes = ncols * nrows;
    g->nedges = 2 * ncols * nrows - ncols - nrows;
  } else {
    Error(MSG1,"CreateGraph");
  }
  DestroyCImage(&clab);
  return(g);
}
Beispiel #2
0
//-----------------------------------------------------------------------------
//  Computes the panel center to world transform
//-----------------------------------------------------------------------------
void C_VGuiScreen::ComputePanelToWorld()
{
	// The origin is at the upper-left corner of the screen
	Vector vecOrigin, vecUR, vecLL;
	ComputeEdges( &vecOrigin, &vecUR, &vecLL );
	m_PanelToWorld.SetupMatrixOrgAngles( vecOrigin, GetAbsAngles() );
}
Beispiel #3
0
//-----------------------------------------------------------------------------
// Return intersection point of ray with screen in barycentric coords
//-----------------------------------------------------------------------------
bool C_VGuiScreen::IntersectWithRay( const Ray_t &ray, float *u, float *v, float *t )
{
	// Perform a raycast to see where in barycentric coordinates the ray hits
	// the viewscreen; if it doesn't hit it, you're not in the mode
	Vector origin, upt, vpt;
	ComputeEdges( &origin, &upt, &vpt );
	return ComputeIntersectionBarycentricCoordinates( ray, origin, upt, vpt, *u, *v, t );
}
Beispiel #4
0
void Polygon2d::Move(float x, float y)
{
    for (unsigned int i = 0; i < vertices.size(); i++)
    {
        vertices[i].x += x;
        vertices[i].y += y;
    }
    ComputeEdges();
}
Beispiel #5
0
//----------------------------------------------------------------------------
VertexCollapse::VertexCollapse (int iVQuantity, Vector3*& rakVertex,
    bool bClosed, int*& raiMap, int& riEQuantity, int*& raiEdge)
{
    raiMap = new int[iVQuantity];

    if ( bClosed )
    {
        riEQuantity = iVQuantity;
        raiEdge = new int[2*riEQuantity];

        if ( iVQuantity == 3 )
        {
            raiMap[0] = 0;
            raiMap[1] = 1;
            raiMap[2] = 3;
            raiEdge[0] = 0;  raiEdge[1] = 1;
            raiEdge[2] = 1;  raiEdge[3] = 2;
            raiEdge[4] = 2;  raiEdge[5] = 0;
            return;
        }
    }
    else
    {
        riEQuantity = iVQuantity-1;
        raiEdge = new int[2*riEQuantity];

        if ( iVQuantity == 2 )
        {
            raiMap[0] = 0;
            raiMap[1] = 1;
            raiEdge[0] = 0;  raiEdge[1] = 1;
            return;
        }
    }

    // create the heap of records
    InitializeHeap(iVQuantity,rakVertex,bClosed);
    BuildHeap();
    assert( IsValid() );

    // create the level of detail information for the polyline
    int* aiCollapse = new int[iVQuantity];
    CollapseVertices(iVQuantity,rakVertex,aiCollapse);
    ComputeEdges(iVQuantity,bClosed,aiCollapse,raiMap,riEQuantity,raiEdge);
    ReorderVertices(iVQuantity,rakVertex,aiCollapse,riEQuantity,raiEdge);
    delete[] aiCollapse;
}
Beispiel #6
0
bool Polygon2d::IsConvex() const
{
    ComputeEdges();
    if ( edges.size() < 3 ) return false;

    bool zProductIsPositive = (edges[0].x*edges[0+1].y - edges[0].y*edges[0+1].x) > 0;

    for (unsigned int i = 1;i<edges.size()-1;++i)
    {
        float zCrossProduct = edges[i].x*edges[i+1].y - edges[i].y*edges[i+1].x;
        if ( (zCrossProduct > 0) != zProductIsPositive ) return false;
    }

    float lastZCrossProduct = edges[edges.size()-1].x*edges[0].y - edges[edges.size()-1].y*edges[0].x;
    if ( (lastZCrossProduct > 0) != zProductIsPositive ) return false;

    return true;
}
Beispiel #7
0
csHazeHullBox::csHazeHullBox(const csVector3& a, const csVector3& b) :
  scfImplementationType(this)
{
  min = a;
  max = b;
  /// fill with data
  total_vert = 8;
  total_poly = 12;
  verts = new csVector3 [total_vert];
  pol_num = new int [total_poly];
  pol_verts = new int* [total_poly];
  int i;
  for(i=0; i<total_poly; i++)
  {
    pol_num[i] = 3;
    pol_verts[i] = new int [ pol_num[i] ];
  }

  verts[0].Set (min.x, min.y, min.z);
  verts[1].Set (max.x, min.y, min.z);
  verts[2].Set (min.x, max.y, min.z);
  verts[3].Set (max.x, max.y, min.z);
  verts[4].Set (min.x, min.y, max.z);
  verts[5].Set (max.x, min.y, max.z);
  verts[6].Set (min.x, max.y, max.z);
  verts[7].Set (max.x, max.y, max.z);

  pol_verts[0][0] = 0; pol_verts[0][1] = 2; pol_verts[0][2] = 3;
  pol_verts[1][0] = 0; pol_verts[1][1] = 3; pol_verts[1][2] = 1;
  pol_verts[2][0] = 1; pol_verts[2][1] = 3; pol_verts[2][2] = 7;
  pol_verts[3][0] = 1; pol_verts[3][1] = 7; pol_verts[3][2] = 5;
  pol_verts[4][0] = 7; pol_verts[4][1] = 4; pol_verts[4][2] = 5;
  pol_verts[5][0] = 7; pol_verts[5][1] = 6; pol_verts[5][2] = 4;
  pol_verts[6][0] = 6; pol_verts[6][1] = 0; pol_verts[6][2] = 4;
  pol_verts[7][0] = 6; pol_verts[7][1] = 2; pol_verts[7][2] = 0;
  pol_verts[8][0] = 6; pol_verts[8][1] = 7; pol_verts[8][2] = 3;
  pol_verts[9][0] = 6; pol_verts[9][1] = 3; pol_verts[9][2] = 2;
  pol_verts[10][0] = 0; pol_verts[10][1] = 1; pol_verts[10][2] = 4;
  pol_verts[11][0] = 1; pol_verts[11][1] = 5; pol_verts[11][2] = 4;

  ComputeEdges();
}
Beispiel #8
0
csHazeHullCone::csHazeHullCone(int nr_sides, const csVector3& start,
  const csVector3& end, float srad, float erad) :
  scfImplementationType(this)
{
  csHazeHullCone::nr_sides = nr_sides;
  csHazeHullCone::start = start;
  csHazeHullCone::end = end;
  start_radius = srad;
  end_radius = erad;

  /// fill with data
  total_vert = nr_sides*2;
  total_poly = nr_sides + 2;
  verts = new csVector3 [total_vert];
  pol_num = new int [total_poly];
  pol_verts = new int* [total_poly];
  int i;

  pol_num[0] = nr_sides;
  pol_num[1] = nr_sides;
  for(i=2; i<total_poly; i++)
  {
    pol_num[i] = 4;
  }

  for(i=0; i<total_poly; i++)
  {
    pol_verts[i] = new int [ pol_num[i] ];
  }

  /// fill each circle in turn
  ConeFillVerts(&verts[0], nr_sides, start, start_radius);
  ConeFillVerts(&verts[nr_sides], nr_sides, end, end_radius);

  /// fill pol_verts
  // caps
  for(i=0; i<nr_sides; i++)
  {
    pol_verts[0][i] = nr_sides + i;
    pol_verts[1][i] = nr_sides-i-1;
  }
  // sides
  int pnum = 2;
  for(i=0; i<nr_sides; i++)
  {
    int nexti = (i+1)%nr_sides;

    pol_verts[pnum][0] = i;
    pol_verts[pnum][1] = nexti;
    pol_verts[pnum][2] = nexti + nr_sides;
    pol_verts[pnum][3] = i + nr_sides;
    pnum++;
    /*
    pol_verts[pnum][0] = i;
    pol_verts[pnum][1] = nexti + nr_sides;
    pol_verts[pnum][2] = i + nr_sides;
    pnum++;
    pol_verts[pnum][0] = i;
    pol_verts[pnum][1] = nexti;
    pol_verts[pnum][2] = nexti + nr_sides;
    pnum++;
    */
  }

  ComputeEdges();
}