Example #1
0
inT32 C_OUTLINE::area() const {
  int stepindex;                 //current step
  inT32 total_steps;             //steps to do
  inT32 total;                   //total area
  ICOORD pos;                    //position of point
  ICOORD next_step;              //step to next pix
  // We aren't going to modify the list, or its contents, but there is
  // no const iterator.
  C_OUTLINE_IT it(const_cast<C_OUTLINE_LIST*>(&children));

  pos = start_pos ();
  total_steps = pathlength ();
  total = 0;
  for (stepindex = 0; stepindex < total_steps; stepindex++) {
                                 //all intersected
    next_step = step (stepindex);
    if (next_step.x () < 0)
      total += pos.y ();
    else if (next_step.x () > 0)
      total -= pos.y ();
    pos += next_step;
  }
  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
    total += it.data ()->area ();//add areas of children

  return total;
}
inT32 C_OUTLINE::area() {  //winding number
  int stepindex;                 //current step
  inT32 total_steps;             //steps to do
  inT32 total;                   //total area
  ICOORD pos;                    //position of point
  ICOORD next_step;              //step to next pix
  C_OUTLINE_IT it = child ();

  pos = start_pos ();
  total_steps = pathlength ();
  total = 0;
  for (stepindex = 0; stepindex < total_steps; stepindex++) {
                                 //all intersected
    next_step = step (stepindex);
    if (next_step.x () < 0)
      total += pos.y ();
    else if (next_step.x () > 0)
      total -= pos.y ();
    pos += next_step;
  }
  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
    total += it.data ()->area ();//add areas of children

  return total;
}
inT32 C_OUTLINE::perimeter() {
  inT32 total_steps;             // Return value.
  C_OUTLINE_IT it = child();

  total_steps = pathlength();
  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward())
    total_steps += it.data()->pathlength();  // Add perimeters of children.

  return total_steps;
}
Example #4
0
inT32 C_OUTLINE::perimeter() const {
  inT32 total_steps;             // Return value.
  // We aren't going to modify the list, or its contents, but there is
  // no const iterator.
  C_OUTLINE_IT it(const_cast<C_OUTLINE_LIST*>(&children));

  total_steps = pathlength();
  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward())
    total_steps += it.data()->pathlength();  // Add perimeters of children.

  return total_steps;
}
// find the shortest path length
int pathlength(const int origin,const int destination, int list[])
{ 

    int shortestlength = 0;
    int l[NUM_V];
    int c=0;
    int le;
    int i;
    list[origin-1]=1;   /*marking current vertices as listed*/
    list[destination-1]=1;
    
	if(graph[origin-1][destination-1]==1 && graph[destination-1][origin-1]==1)   /*if destination directly connecting to current vertex*/              
		return 1;
	
	for(i=0;i<NUM_V;i++)
	{
		if(list[i]==0) /*checking if untraversed*/
		{
			c++;
			break;	   
    	}	
    }
    
    if(c==0)
    	return 0;
    	
    for(i=0;i<NUM_V;i++)
    {
    	if(graph[origin-1][i]==1 && list[i]==0) /*checking for directly connected unvisited vertices*/
    	{
    		le=pathlength(i+1,destination,list);  /*recursion*/
    		
    		if(shortestlength==0)
    			shortestlength=le;	
    		else if(le<shortestlength)
    			shortestlength=le;
    	}		
    }	
    	
    if(shortestlength==0)
    	return shortestlength;
    
    shortestlength++;	
    return shortestlength;
}
// main function: display the right messages. Please refer to MP5 requirement
 int main(int argc, const char **argv)
{
    int gc;
    int list[NUM_V];
    int origin;
    int destination;
    int sl;
    int i;
    
    if(argv[1]==NULL)
    {
    	printf("enter the input file name\n");
    	return -1;
    }
    
    gc = graph_reading(argv[1]); 
    
    if(gc==1)
    {
    	printf("input file cannot be opened\n");
    	return -1;
    }
    else
    	printf("The adjacency matrix has been loaded\n");
    
    graph_print();
    
    printf("Enter the origin vertex:\n");
    scanf("%d",&origin);
    printf("Enter the destination vertex:\n");
    scanf("%d",&destination);
    
    for(i=0;i<NUM_V;i++)  /*list[NUM_V] has recored of traversed vertices*/
    	list[NUM_V]=0;
    	
    sl = pathlength(origin,destination,list); /*shortest path length*/
    
    if(sl==0)
    	printf("%d and %d are seperated forever!",origin,destination);
    else
    	printf("%d needs %d step(s) to get %d",origin,sl,destination); 
     	
    
    return 0;
}
Example #7
0
inT32 C_OUTLINE::outer_area() const {
  int stepindex;                 //current step
  inT32 total_steps;             //steps to do
  inT32 total;                   //total area
  ICOORD pos;                    //position of point
  ICOORD next_step;              //step to next pix

  pos = start_pos ();
  total_steps = pathlength ();
  if (total_steps == 0)
    return box.area();
  total = 0;
  for (stepindex = 0; stepindex < total_steps; stepindex++) {
                                 //all intersected
    next_step = step (stepindex);
    if (next_step.x () < 0)
      total += pos.y ();
    else if (next_step.x () > 0)
      total -= pos.y ();
    pos += next_step;
  }

  return total;
}
Example #8
0
inT32 C_OUTLINE::count_transitions(                 //winding number
                                   inT32 threshold  //on size
                                  ) {
  BOOL8 first_was_max_x;         //what was first
  BOOL8 first_was_max_y;
  BOOL8 looking_for_max_x;       //what is next
  BOOL8 looking_for_min_x;
  BOOL8 looking_for_max_y;       //what is next
  BOOL8 looking_for_min_y;
  int stepindex;                 //current step
  inT32 total_steps;             //steps to do
                                 //current limits
  inT32 max_x, min_x, max_y, min_y;
  inT32 initial_x, initial_y;    //initial limits
  inT32 total;                   //total changes
  ICOORD pos;                    //position of point
  ICOORD next_step;              //step to next pix

  pos = start_pos ();
  total_steps = pathlength ();
  total = 0;
  max_x = min_x = pos.x ();
  max_y = min_y = pos.y ();
  looking_for_max_x = TRUE;
  looking_for_min_x = TRUE;
  looking_for_max_y = TRUE;
  looking_for_min_y = TRUE;
  first_was_max_x = FALSE;
  first_was_max_y = FALSE;
  initial_x = pos.x ();
  initial_y = pos.y ();          //stop uninit warning
  for (stepindex = 0; stepindex < total_steps; stepindex++) {
                                 //all intersected
    next_step = step (stepindex);
    pos += next_step;
    if (next_step.x () < 0) {
      if (looking_for_max_x && pos.x () < min_x)
        min_x = pos.x ();
      if (looking_for_min_x && max_x - pos.x () > threshold) {
        if (looking_for_max_x) {
          initial_x = max_x;
          first_was_max_x = FALSE;
        }
        total++;
        looking_for_max_x = TRUE;
        looking_for_min_x = FALSE;
        min_x = pos.x ();        //reset min
      }
    }
    else if (next_step.x () > 0) {
      if (looking_for_min_x && pos.x () > max_x)
        max_x = pos.x ();
      if (looking_for_max_x && pos.x () - min_x > threshold) {
        if (looking_for_min_x) {
          initial_x = min_x;     //remember first min
          first_was_max_x = TRUE;
        }
        total++;
        looking_for_max_x = FALSE;
        looking_for_min_x = TRUE;
        max_x = pos.x ();
      }
    }
    else if (next_step.y () < 0) {
      if (looking_for_max_y && pos.y () < min_y)
        min_y = pos.y ();
      if (looking_for_min_y && max_y - pos.y () > threshold) {
        if (looking_for_max_y) {
          initial_y = max_y;     //remember first max
          first_was_max_y = FALSE;
        }
        total++;
        looking_for_max_y = TRUE;
        looking_for_min_y = FALSE;
        min_y = pos.y ();        //reset min
      }
    }
    else {
      if (looking_for_min_y && pos.y () > max_y)
        max_y = pos.y ();
      if (looking_for_max_y && pos.y () - min_y > threshold) {
        if (looking_for_min_y) {
          initial_y = min_y;     //remember first min
          first_was_max_y = TRUE;
        }
        total++;
        looking_for_max_y = FALSE;
        looking_for_min_y = TRUE;
        max_y = pos.y ();
      }
    }

  }
  if (first_was_max_x && looking_for_min_x) {
    if (max_x - initial_x > threshold)
      total++;
    else
      total--;
  }
  else if (!first_was_max_x && looking_for_max_x) {
    if (initial_x - min_x > threshold)
      total++;
    else
      total--;
  }
  if (first_was_max_y && looking_for_min_y) {
    if (max_y - initial_y > threshold)
      total++;
    else
      total--;
  }
  else if (!first_was_max_y && looking_for_max_y) {
    if (initial_y - min_y > threshold)
      total++;
    else
      total--;
  }

  return total;
}