Example #1
0
Bezier::Bezier( intf_thread_t *p_intf, const vector<float> &rAbscissas,
                const vector<float> &rOrdinates, Flag_t flag )
    : SkinObject( p_intf )
{
    // Copy the control points coordinates
    m_ptx.assign( rAbscissas.begin(), rAbscissas.end() );
    m_pty.assign( rOrdinates.begin(), rOrdinates.end() );

    // We expect m_ptx and m_pty to have the same size, of course
    m_nbCtrlPt = m_ptx.size();

    // Precalculate the factoriels
    m_ft.push_back( 1 );
    for( int i = 1; i < m_nbCtrlPt; i++ )
    {
        m_ft.push_back( i * m_ft[i - 1] );
    }

    // Calculate the first point
    int oldx, oldy;
    computePoint( 0, oldx, oldy );
    m_leftVect.push_back( oldx );
    m_topVect.push_back( oldy );
    m_percVect.push_back( 0 );

    // Calculate the other points
    float percentage;
    int cx, cy;
    for( float j = 1; j <= MAX_BEZIER_POINT; j++ )
    {
        percentage = j / MAX_BEZIER_POINT;
        computePoint( percentage, cx, cy );
        if( ( flag == kCoordsBoth && ( cx != oldx || cy != oldy ) ) ||
            ( flag == kCoordsX && cx != oldx ) ||
            ( flag == kCoordsY && cy != oldy ) )
        {
            m_percVect.push_back( percentage );
            m_leftVect.push_back( cx );
            m_topVect.push_back( cy );
            oldx = cx;
            oldy = cy;
        }
    }
    m_nbPoints = m_leftVect.size();

    // If we have only one control point, we duplicate it
    // This allows to simplify the algorithms used in the class
    if( m_nbPoints == 1 )
    {
        m_leftVect.push_back( m_leftVect[0] );
        m_topVect.push_back( m_topVect[0] );
        m_percVect.push_back( 1 );
        m_nbPoints = 2;
   }

    // Ensure that the percentage of the last point is always 1
    m_percVect[m_nbPoints - 1] = 1;
}
void computeScreenQuad(
					   const D3DXMATRIX& inverseview, const D3DXMATRIX& view, const D3DXMATRIX& proj,
					   BYTE* verts, BYTE* colors, DWORD stride, 
					   const Vector& p0, DWORD col0, float size0, 
					   const Vector& p1, DWORD col1, float size1, bool constantsize) 
{
	// Compute delta in camera space
	Vector Delta;
	transPoint3x3(Delta, p1-p0, view);
	
	// Compute size factors
	float SizeP0 = size0;
	float SizeP1 = size1;
/*	
	if(constantsize)
	{
		// Compute scales so that screen-size is constant
		SizeP0 *= computeConstantScale(p0, view, proj);
		SizeP1 *= computeConstantScale(p1, view, proj);
	}
*/	
	// Compute quad vertices
	float Theta0 = atan2f(-Delta.x, -Delta.y);
	float c0 = SizeP0 * cosf(Theta0);
	float s0 = SizeP0 * sinf(Theta0);
	computePoint(*((Vector*)verts),  c0, -s0, inverseview, p0); verts+=stride;
	computePoint(*((Vector*)verts),  -c0, s0, inverseview, p0); verts+=stride;
	
	float Theta1 = atan2f(Delta.x, Delta.y);
	float c1 = SizeP1 * cosf(Theta1);
	float s1 = SizeP1 * sinf(Theta1);
	computePoint(*((Vector*)verts),  -c1, s1, inverseview, p1); verts+=stride;
	computePoint(*((Vector*)verts),  c1, -s1, inverseview, p1); verts+=stride;

/*	
	// Output uvs if needed
	if(uvs)
	{
		*((float*)uvs) = 0.0f; *((float*)(uvs+4)) = 1.0f; uvs+=stride;
		*((float*)uvs) = 0.0f; *((float*)(uvs+4)) = 0.0f; uvs+=stride;
		*((float*)uvs) = 1.0f; *((float*)(uvs+4)) = 1.0f; uvs+=stride;
		*((float*)uvs) = 1.0f; *((float*)(uvs+4)) = 0.0f; uvs+=stride;
	}
*/
	
	// Output color if needed
	if(colors) {
		*((DWORD*)colors) = col0; colors+=stride;	
		*((DWORD*)colors) = col0; colors+=stride;	
		*((DWORD*)colors) = col1; colors+=stride;	
		*((DWORD*)colors) = col1; colors+=stride;	
	}
	
}
Example #3
0
template <typename PointInT, typename PointNT, typename PointOutT> void
pcl::ShapeContext3DEstimation<PointInT, PointNT, PointOutT>::computeFeature (PointCloudOut &output)
{
  assert (descriptor_length_ == 1980);

  output.is_dense = true;
  // Iterate over all points and compute the descriptors
	for (size_t point_index = 0; point_index < indices_->size (); point_index++)
  {
    //output[point_index].descriptor.resize (descriptor_length_);

    // If the point is not finite, set the descriptor to NaN and continue
    if (!isFinite ((*input_)[(*indices_)[point_index]]))
    {
      for (size_t i = 0; i < descriptor_length_; ++i)
        output[point_index].descriptor[i] = std::numeric_limits<float>::quiet_NaN ();

      memset (output[point_index].rf, 0, sizeof (output[point_index].rf[0]) * 9);
      output.is_dense = false;
      continue;
    }

    std::vector<float> descriptor (descriptor_length_);
    if (!computePoint (point_index, *normals_, output[point_index].rf, descriptor))
      output.is_dense = false;
    for (size_t j = 0; j < descriptor_length_; ++j)
      output[point_index].descriptor[j] = descriptor[j];
  }
}
Example #4
0
// -----------------------------------------------------------------
//
// @details This manages the computation of the pixels for which this
// task is responsible.
//
// -----------------------------------------------------------------
void MandelTask::execute()
{
    //
    // Compute this only one time for all pixels.
    auto log2MaxIterations = std::log2(std::log(m_maxIterations));

    //
    // Now that we are about to do some work, reserve the memory we need to store the results.
    uint16_t rows = (m_endRow - m_startRow) + 1;
    m_pixels.resize(rows * m_sizeX);

    //
    // Premature optimization, I know, but just can't help myself.
    auto pixels = m_pixels.data();

    double currentY = m_startY;
    for (int row = 0; row < rows; row++, currentY += m_deltaY)
    {
        double currentX = m_startX;
        for (int x = 0; x < m_sizeX; x++, currentX += m_deltaX)
        {
            auto iterations = computePoint(currentX, currentY, m_maxIterations);

            //
            // Use the smooth coloring algorithm to determine the color index;
            double colorIndex = iterations - log2MaxIterations;
            colorIndex = (colorIndex / m_maxIterations) * 768;
            colorIndex = std::min(colorIndex, 767.0);
            colorIndex = std::max(colorIndex, 0.0);

            pixels[row * m_sizeX + x] = static_cast<uint16_t>(colorIndex);
        }
    }
}
Example #5
0
Vect RayTracer::computeDirection(uint x, uint y) {
    Point_2D p = computePoint(x, y);
    Vect dx = (horizontal()).linearMult(2 * p.x - 1);
    Vect dy = (vertical()).linearMult(2 * p.y - 1);

    Vect dir = imageCenter + dx + dy;
    // dir.normalize(); TODO: fix tests
    return dir;
}
BSpline::BSpline(int m, int n, int resolution, BSPoint *control)
    :n_control_points(m), n_degree(n), knots(std::vector<int>(m+n+2, 0)), curve(new CvPoint[resolution])
{
	double increment, interval;
	BSPoint tmp_point;
	int output_index;
    
	computeKnots();
	increment = (double) (m - n + 1)/(resolution - 1); // why ?
	interval = 0;    

    for (output_index = 0; output_index < resolution - 1; ++output_index){
        computePoint(control, &tmp_point, interval);
        curve[output_index].x = round(tmp_point.x);
        curve[output_index].y = round(tmp_point.y);
        interval += increment;
    }
	curve[resolution-1].x=control[m].x;
	curve[resolution-1].y=control[m].y;
}
int main(int argc, char** argv) {

	// mandelbrot
	int* pixels;
	int i, j;
	int color;
	
	// mpi
	int nproc, iproc;
	int* mySendArr;
	int* myRecvArr;
	MPI_Status status;
	
	// miscellaneous
	int loop; // used as boolean
	int loopCount;
	
	MPI_Init(&argc, &argv);
	MPI_Comm_size(MPI_COMM_WORLD, &nproc);
	MPI_Comm_rank(MPI_COMM_WORLD, &iproc);
	
	// everyone needs a send and a recv array
	// the extra 1 is for the start location
	mySendArr = (int*)malloc((BLOCK_WIDTH * BLOCK_HEIGHT + 1) * sizeof(int));
	myRecvArr = (int*)malloc((BLOCK_WIDTH * BLOCK_HEIGHT + 1) * sizeof(int));
	
	
	if (iproc == 0) {	// master code
		int numJobs;
		int jobCount;
		int jobStart;
		double timestart, timefinish, timetaken;
		
		numJobs = NUM_JOBS;
		jobCount = 0;
		
		//fprintf(stderr,"(%d) I'm the master\n",iproc);
		pixels = (int*)malloc(WIDTH * HEIGHT * sizeof(int));
		
		timestart = When();
		
	/*
		for (j = 0; j < HEIGHT; j++) {
			for (i = 0; i < WIDTH; i++) {
				pixels[i + j * WIDTH] = computePoint(i, j);
			}
		}
	*/	
		//loop = 1;
		for (loopCount = 0; loopCount < (NUM_JOBS * 2 + nproc - 1); loopCount++) {
			//fprintf(stderr,"(%d) I'm waiting\n",iproc);
			
			MPI_Recv(myRecvArr,1,MPI_INT,MPI_ANY_SOURCE,0,MPI_COMM_WORLD,&status);
		//	fprintf(stderr,"(%d) %d sent me a message: %lf\n",iproc,status.MPI_SOURCE,myRecvArr[0]);
			
			if (myRecvArr[0] == -1) {	// worker wants more work
				//fprintf(stderr,"(%d) %d wants more work\n",iproc,status.MPI_SOURCE);
				
				if (numJobs > 0) {
					// tell worker there is a job starting at numJobs - 1 * BLOCK_WIDTH
					mySendArr[0] = jobCount * BLOCK_WIDTH;
					jobCount++;
					MPI_Send(mySendArr,1,MPI_INT,status.MPI_SOURCE,0,MPI_COMM_WORLD);
					numJobs--;
				}
				else {
					// tell worker there isn't any more
					mySendArr[0] = -1;
					MPI_Send(mySendArr,1,MPI_INT,status.MPI_SOURCE,0,MPI_COMM_WORLD);
				}
				
				
			}
			else if (myRecvArr[0] == -2) {	// worker wants to send finished work
				//fprintf(stderr,"(%d) %d wants to send me their work\n",iproc,status.MPI_SOURCE);
			
				MPI_Recv(myRecvArr,BLOCK_WIDTH * BLOCK_HEIGHT + 1,MPI_INT,status.MPI_SOURCE,0,MPI_COMM_WORLD,&status);
				
				// worker sent work with start number
				//fprintf(stderr,"(%d) %d sent me their work starting at %d\n",iproc,status.MPI_SOURCE,myRecvArr[0]);
				
				// copy work into pixel array
				jobStart = myRecvArr[0];
				for (i = 1; i < BLOCK_WIDTH * BLOCK_HEIGHT + 1; i++) {
					pixels[i-1 + jobStart] = myRecvArr[i];
					//fprintf(stderr,"%d ",pixels[i-1 + jobStart]);
				}
			}

			
			//loop = 0;
		}
		
		
		timefinish = When();
		timetaken = timefinish - timestart;
		//fprintf(stderr,"(%d) I'm finished\n",iproc);
		fprintf(stdout,"(%d) Time taken: %lf\n",iproc,timetaken);
	
		fileWrite(pixels);
		free(pixels);
	
	
	}
	else {	// worker code
		int myJobStart;
		//fprintf(stderr,"\t(%d) I'm a worker\n",iproc);
		pixels = (int*)malloc(BLOCK_WIDTH * BLOCK_HEIGHT * sizeof(int));
		
		loop = 1;
		while (loop) {
			// ask master for work
			mySendArr[0] = -1;
			MPI_Send(mySendArr,1,MPI_INT,0,0,MPI_COMM_WORLD);
			
			// recv response (starting number or -1)
			MPI_Recv(myRecvArr,1,MPI_INT,0,0,MPI_COMM_WORLD,&status);
			
			if (myRecvArr[0] == -1) {	// -1 means no more
				//fprintf(stderr,"\t(%d) Master says no more work\n",iproc);
				loop = 0;
				
			}
			else {
				//fprintf(stderr,"\t(%d) Master gave me start of %d\n",iproc,myRecvArr[0]);
				myJobStart = myRecvArr[0];
				
				
				// do work
				#pragma omp parallel for private(i, j)
				for (j = 0; j < BLOCK_HEIGHT; j++) {
					for (i = 0; i < BLOCK_WIDTH; i++) {
						pixels[i + j * BLOCK_WIDTH] = computePoint(i, j + myJobStart / 1536);
						//fprintf(stderr,"%d ",pixels[i + j * BLOCK_WIDTH]);
					}
				}
				
				
				// tell master work is done and ready to send
				mySendArr[0] = -2;
				MPI_Send(mySendArr,1,MPI_INT,0,0,MPI_COMM_WORLD);
				
				// send work
				mySendArr[0] = myJobStart;
				for (i = 1; i < BLOCK_WIDTH * BLOCK_HEIGHT + 1; i++) {
					mySendArr[i] = pixels[i-1];
				}
				
				MPI_Send(mySendArr,BLOCK_WIDTH * BLOCK_HEIGHT + 1,MPI_INT,0,0,MPI_COMM_WORLD);
				
			}

			
		}
		
		
		//fprintf(stderr,"\t(%d) I'm finished\n",iproc);
		
	}

	
	
	MPI_Finalize();
	
	return 0;
}
void BezierPatch::calculatePoints()
{
    float dt=0.06;
    pointCounter = 0;
    //draw columns
    for(float i=0;i<1.01f;i+=u)
    {
        for(float j=0;j<1.01f +dt/2;j+=dt)
        {
            if(j>1) j= 1.0f;
            pointToDraw = vec4(computePoint(i,j),1);
            if(!camera->isStereoscopic){
                pointToDraw = camera->transformationMatrix* pointToDraw;
                pointToDraw.x = pointToDraw.x / pointToDraw.w;
                pointToDraw.y = pointToDraw.y / pointToDraw.w;
                pointToDraw.x /= camera->xRatio;
                pointToDraw.y /= camera->yRatio;
                pixelVector[pointCounter] = vec4(pointToDraw);
                pointCounter++;
            }
            else{
                vec4 point2 = vec4(pointToDraw);
                pointToDraw = camera->transformationMatrixLeftEye * pointToDraw;
                pointToDraw.x /= pointToDraw.w;
                pointToDraw.y /= pointToDraw.w;
                pointToDraw.x /= camera->xRatio;
                pointToDraw.y /= camera->yRatio;
                leftEyePixelVector[pointCounter] = vec4(pointToDraw);

                point2 = camera->transformationMatrixRightEye * point2;
                point2.x /= point2.w;
                point2.y /= point2.w;
                point2.x /= camera->xRatio;
                point2.y /= camera->yRatio;
                rightEyePixelVector[pointCounter] = vec4(point2);
                pointCounter++;
            }
            if(j==1.0f)break;
        }
    }

    for(float i=0;i<1.01f;i+=v)
    {
        for(float j=0;j<1.01f+dt/2;j+=dt)
        {
            if(j>1) j= 1.0f;
            pointToDraw = vec4(computePoint(j,i),1);
                if(!camera->isStereoscopic){
                    pointToDraw = camera->transformationMatrix* pointToDraw;
                    pointToDraw.x = pointToDraw.x / pointToDraw.w;
                    pointToDraw.y = pointToDraw.y / pointToDraw.w;
                    pointToDraw.x /= camera->xRatio;
                    pointToDraw.y /= camera->yRatio;
                    pixelVector[pointCounter] = vec4(pointToDraw);
                    pointCounter++;
                }
                else{
                    vec4 point2 = vec4(pointToDraw);
                    pointToDraw = camera->transformationMatrixLeftEye * pointToDraw;
                    pointToDraw.x /= pointToDraw.w;
                    pointToDraw.y /= pointToDraw.w;
                    pointToDraw.x /= camera->xRatio;
                    pointToDraw.y /= camera->yRatio;
                    leftEyePixelVector[pointCounter] = vec4(pointToDraw);

                    point2 = camera->transformationMatrixRightEye * point2;
                    point2.x /= point2.w;
                    point2.y /= point2.w;
                    point2.x /= camera->xRatio;
                    point2.y /= camera->yRatio;
                    rightEyePixelVector[pointCounter] = vec4(point2);
                    pointCounter++;
                }
                if(j==1.0f)break;
        }
    }
}