find the rightmost and leftmost number in a point cloud of text file

Nov 27, 2011 at 1:03am
Hi,everyone. I am trying to do a program about convex hull. But i am stuck in the first step. That is find the rightmost and leftmost point in the point cloud. In the text file,there have 33456 points. Can anyone help me in this problem? Because i am still a beginner in c++ programming. I will appreciate for your help. Thanks.
Last edited on Nov 27, 2011 at 1:17am
Nov 27, 2011 at 3:02am
The rightmost point is the one with the biggest 'x' value.
The leftmost point is the one with the lowest 'x' value.

¿what is the problem?
Nov 27, 2011 at 5:40am
Sorry, i didn't mention well in my question just now. I mean if i write a program. How can i ask the program to detect the rightmost and leftmost number inside the point cloud file? there are 33456points in the text file. I need to read the text file. then find the rightmost and leftmost point.
Nov 27, 2011 at 12:55pm
max_element( s.begin(), s.end(), check_out_the_x_coordinate );
It may be a good idea to store the points in a container, to avoid several traverses of the file.
Nov 27, 2011 at 1:43pm
or could it be that reading the file one by one line getting the right most error and then comaparing the elements like the function

1
2
3
4
int compare(int a, int b) 
{
  return ( a > b) ? a : b ; 
}

please correct me if i am wroing .. i agree with ne555 from the performance point of view are the point are in large number .
Last edited on Nov 27, 2011 at 1:43pm
Nov 27, 2011 at 9:36pm
ok. Thanks guys. I am using this code to read my file. How can i compare it?
Because i am doing computer graphics also. So it may consists some opengl terms.
Or anyone know any website that i can refer to? As my tutorial. Cause i am still new in programming.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "graphics.h"

#include <iostream>
void CPrimitive::LoadObject(char *file, CPrimitive *obj = new CPrimitive)
{
	FILE*fp = fopen(file,"r");

	fscanf(fp,"%d",&TempNum);
	obj->NumTri = TempNum;
	for(i=0;i<obj->NumTri;i++)
	{
		fscanf(fp,"%f %f %f", &A[i].x,&A[i].y,&A[i].z);
		fscanf(fp,"%f %f %f", &B[i].x,&B[i].y,&B[i].z);
		fscanf(fp,"%f %f %f", &C[i].x,&C[i].y,&C[i].z);
	}

	fclose(fp);
}

void CPrimitive::Draw(CPrimitive *obj=new CPrimitive)
{
	glPushMatrix();
	glBegin(GL_POINTS);
	for(int j=0;j<obj->NumTri;j++)
	{
		glVertex3fv(&A[j].x);
		glVertex3fv(&B[j].x);
		glVertex3fv(&C[j].x);
	}


	glEnd();
	glPopMatrix();
}
Topic archived. No new replies allowed.