Esempio n. 1
0
    /**
     * \return Returns the weights for the covariance of the points as a vector
     */
    WeightVector covariance_weights_vector() const noexcept
    {
        const int point_count = count_points();

        WeightVector weight_vec(point_count);

        for (int i = 0; i < point_count; ++i)
        {
            weight_vec(i) = weights_(i).w_cov;
        }

        return weight_vec;
    }
Esempio n. 2
0
    /**
     * Resizes a dynamic-size PointSet
     *
     * \param Points_   Number of points
     *
     * \throws ResizingFixedSizeEntityException
     */
    void resize(int dim, int points_count)
    {
        if (dim == dimension() && points_count == count_points()) return;

        points_.setZero(dim, points_count);

        weights_.resize(points_count, 1);
        const double weight = (points_count > 0)? 1. / double(points_count) : 0;
        for (int i = 0; i < points_count; ++i)
        {
            weights_(i).w_mean = weight;
            weights_(i).w_cov = weight;
        }
    }
Esempio n. 3
0
int		*place_token(t_filler *fil)
{
	int i;
	int j;

	i = 0;
	fil->min = INT_MAX;
	while (i <= fil->map_h - fil->token_h)
	{
		j = 0;
		while (j <= fil->map_w - fil->token_w)
		{
			if (check_spot(fil, i, j) && count_points(fil, i, j))
			{
				fil->i = i;
				fil->j = j;
			}
			j++;
		}
		i++;
	}
	return (0);
}
Esempio n. 4
0
/* Given a brushstroke, draw it onto the surface at the specified
 * position and zoom level.
 */
void icCanvasManager::GL::Renderer::draw_stroke(icCanvasManager::RefPtr<icCanvasManager::BrushStroke> br) {
    GLuint strokeInfoTex[4];

    this->ex->glGenTextures(4, strokeInfoTex);

    //Pull the brushstroke information out into a texture.
    size_t strokeTexSize = br->_curve.count_points() * 4 * 2; //Number of texels
    int32_t *strokeTexMem = (int32_t*)malloc(strokeTexSize * 4 * sizeof(int32_t)); //Actual texture memory

    for (int i = 0; i < br->_curve.count_points(); i++) { //Forall polynomials
        for (int j = 0; j < 4; j++) { //Forall control points
            int base_component = i * 4 * 2 * 4 + j * 2 * 4;
            auto &cpt = br->_curve.get_point(i, j);

            strokeTexMem[base_component] = cpt.x;
            strokeTexMem[base_component + 1] = cpt.y;
            strokeTexMem[base_component + 2] = cpt.dx;
            strokeTexMem[base_component + 3] = cpt.dy;
            strokeTexMem[base_component + 4] = cpt.tilt;
            strokeTexMem[base_component + 5] = cpt.angle;
            strokeTexMem[base_component + 6] = cpt.pressure;
            strokeTexMem[base_component + 7] = 0;
        }
    }

    this->ex->glBindTexture(GL_TEXTURE_1D, strokeInfoTex[0]);
    this->ex->glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA32I, strokeTexSize, 0, GL_RGBA_INTEGER, GL_INT, (GLvoid*)strokeTexMem);

    //Pull the derivative stroke information into a texture.
    auto curveDeriv = br->_curve.derivative();
    size_t strokeDerivTexSize = curveDeriv.count_points() * 3 * 2; //Number of texels
    int32_t *strokeDerivTexMem = (int32_t*)malloc(strokeDerivTexSize * 4 * sizeof(int32_t)); //Actual texture memory

    for (int i = 0; i < curveDeriv.count_points(); i++) { //Forall polynomials
        for (int j = 0; j < 3; j++) { //Forall control points
            int base_component = i * 3 * 2 * 4 + j * 2 * 4;
            auto &cpt = curveDeriv.get_point(i, j);

            strokeDerivTexMem[base_component] = cpt.x;
            strokeDerivTexMem[base_component + 1] = cpt.y;
            strokeDerivTexMem[base_component + 2] = cpt.dx;
            strokeDerivTexMem[base_component + 3] = cpt.dy;
            strokeDerivTexMem[base_component + 4] = cpt.tilt;
            strokeDerivTexMem[base_component + 5] = cpt.angle;
            strokeDerivTexMem[base_component + 6] = cpt.pressure;
            strokeDerivTexMem[base_component + 7] = 0;
        }
    }

    this->ex->glBindTexture(GL_TEXTURE_1D, strokeInfoTex[1]);
    this->ex->glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA32I, strokeDerivTexSize, 0, GL_RGBA_INTEGER, GL_INT, (GLvoid*)strokeDerivTexMem);

    //TODO: Actually free texture memory. This is an obvious leak.

    size_t polynomTexSize = curveDeriv.count_points();
    float *polynomTexMem = (float*)malloc(polynomTexSize * 4 * sizeof(float)); //Actual texture memory

    //We also need to calculate memory size for the LUT in this pass
    float pixelInterval = 5.0 / this->xscale;
    float totalLength = 0;
    size_t lutSize = 0;

    for (int i = 0; i < curveDeriv.count_points(); i++) {
        polynomTexMem[i * 4] = this->curve_arc_length(i, curveDeriv);
        totalLength += polynomTexMem[i * 4];
        lutSize += (int)std::ceil(polynomTexMem[i * 4] / pixelInterval);
    }

    this->ex->glBindTexture(GL_TEXTURE_1D, strokeInfoTex[2]);
    this->ex->glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA32F, polynomTexSize, 0, GL_RGBA, GL_FLOAT, (GLvoid*)polynomTexMem);

    //Compute a linearized beizer curve look-up table to avoid
    //expensive in-shader linearization.

    std::cout << "GL: Allocating " << lutSize << " floats!" << std::endl;

    float* lutMemory = (float*)malloc(lutSize * sizeof(float));
    float* curLutMemory = lutMemory;
    for (int i = 0; i < curveDeriv.count_points(); i++) {
        int currentLutSize = (int)std::ceil(polynomTexMem[i * 4] / pixelInterval);

        this->compute_linear_LUT(i, br->_curve, curveDeriv, curLutMemory, currentLutSize, pixelInterval);

        curLutMemory += currentLutSize;
    }

    this->ex->glBindTexture(GL_TEXTURE_1D, strokeInfoTex[3]);
    this->ex->glTexImage1D(GL_TEXTURE_1D, 0, GL_R32F, lutSize, 0, GL_RED, GL_FLOAT, (GLvoid*)lutMemory);

    //Set up the "raymarch" quad so we can raster over the whole tile.
    this->ex->glBindVertexArray(this->raymarchGeom);

    //Set up our framebuffer target.
    this->ex->glBindFramebuffer(GL_DRAW_FRAMEBUFFER, this->renderTarget);

    //Set up our shader program.
    this->ex->glUseProgram(this->dProgram);

    //Set up per-stroke uniforms.
    GLint splineDataLoc, splineDerivativeDataLoc, polynomDataLoc, tintOpacityLoc, brushSizeLoc, lutDataLoc;
    splineDataLoc = this->ex->glGetUniformLocation(this->dProgram, "splineData");
    splineDerivativeDataLoc = this->ex->glGetUniformLocation(this->dProgram, "splineDerivativeData");
    polynomDataLoc = this->ex->glGetUniformLocation(this->dProgram, "polynomData");
    lutDataLoc = this->ex->glGetUniformLocation(this->dProgram, "lutData");
    tintOpacityLoc = this->ex->glGetUniformLocation(this->dProgram, "tintOpacity");
    brushSizeLoc = this->ex->glGetUniformLocation(this->dProgram, "brushSize");

    if (splineDataLoc != -1) {
        this->ex->glUniform1i(splineDataLoc, 0);
        this->ex->glActiveTexture(GL_TEXTURE0 + 0);
        this->ex->glBindTexture(GL_TEXTURE_1D, strokeInfoTex[0]);
        this->ex->glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        this->ex->glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        this->ex->glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    }

    if (splineDerivativeDataLoc != -1) {
        this->ex->glUniform1i(splineDerivativeDataLoc, 1);
        this->ex->glActiveTexture(GL_TEXTURE0 + 1);
        this->ex->glBindTexture(GL_TEXTURE_1D, strokeInfoTex[1]);
        this->ex->glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        this->ex->glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        this->ex->glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    }

    if (polynomDataLoc != -1) {
        this->ex->glUniform1i(polynomDataLoc, 2);
        this->ex->glActiveTexture(GL_TEXTURE0 + 2);
        this->ex->glBindTexture(GL_TEXTURE_1D, strokeInfoTex[2]);
        this->ex->glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        this->ex->glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        this->ex->glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    }

    if (lutDataLoc != -1) {
        this->ex->glUniform1i(lutDataLoc, 3);
        this->ex->glActiveTexture(GL_TEXTURE0 + 3);
        this->ex->glBindTexture(GL_TEXTURE_1D, strokeInfoTex[3]);
        this->ex->glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        this->ex->glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        this->ex->glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    }

    if (tintOpacityLoc != -1) {
        auto premulR = ((float)br->_tint_color_red / icCanvasManager::BrushStroke::COLOR_MAX) * ((float)br->_tint_alpha / icCanvasManager::BrushStroke::COLOR_MAX);
        auto premulG = ((float)br->_tint_color_green / icCanvasManager::BrushStroke::COLOR_MAX) * ((float)br->_tint_alpha / icCanvasManager::BrushStroke::COLOR_MAX);
        auto premulB = ((float)br->_tint_color_blue / icCanvasManager::BrushStroke::COLOR_MAX) * ((float)br->_tint_alpha / icCanvasManager::BrushStroke::COLOR_MAX);
        auto premulA = ((float)br->_tint_alpha / icCanvasManager::BrushStroke::COLOR_MAX);

        this->ex->glUniform4f(tintOpacityLoc, premulR, premulG, premulB, premulA);
    }

    if (brushSizeLoc != -1) {
        this->ex->glUniform1i(brushSizeLoc, br->_base_thickness);
    }

    //Enable transparency
    this->ex->glEnable(GL_BLEND);
    this->ex->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    this->ex->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

    //Cleanup some GL state.
    this->ex->glDisable(GL_BLEND);
    this->ex->glBindVertexArray(0);
    this->ex->glActiveTexture(GL_TEXTURE0);
    this->ex->glUseProgram(0);
    this->ex->glBindTexture(GL_TEXTURE_1D, 0);
    this->ex->glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);

    this->ex->glDeleteTextures(4, strokeInfoTex);

    auto error = this->ex->glGetError();
    assert(error == GL_NO_ERROR);
};
Esempio n. 5
0
 /**
  * Sets the new dimension for dynamic-size points (not to confuse
  * with the number of points)
  *
  * \param dim  Dimension of each point
  */
 void dimension(int dim)
 {
     points_.resize(dim, count_points());
 }
Esempio n. 6
0
int main(int argc,char *argv[]) {
	
  Matrix *C1, *P1;
  Polyhedron *C, *P, *S;
  Polyhedron *CC, *PP;
  Enumeration *en;
  Value *p;
  int i,j,k;
  int m,M;
  char str[1024];
  Value c;

  /******* Read the input *********/
  P1 = Matrix_Read();
  C1 = Matrix_Read();
  if(C1->NbColumns < 2) {
    fprintf(stderr,"Not enough parameters !\n");
    exit(0);
  }
  P = Constraints2Polyhedron(P1, MAXRAYS);
  C = Constraints2Polyhedron(C1, MAXRAYS);
  Matrix_Free(C1);
  Matrix_Free(P1);
  
  
  /******* Compute the true context *******/
  CC = align_context(C,P->Dimension,MAXRAYS);
  PP = DomainIntersection(P,CC,MAXRAYS);
  Domain_Free(CC);
  C1 = Matrix_Alloc(C->Dimension+1,P->Dimension+1);
  for(i=0;i<C1->NbRows;i++)
    for(j=0;j<C1->NbColumns;j++)
      if(i==j-P->Dimension+C->Dimension)
	value_set_si(C1->p[i][j],1);
      else
	value_set_si(C1->p[i][j],0);
  CC = Polyhedron_Image(PP,C1,MAXRAYS);
  Domain_Free(C);
  Domain_Free(PP);
  Matrix_Free(C1);
  C = CC;
  
  /******* Initialize parameters *********/
  p = (Value *)malloc(sizeof(Value) * (P->Dimension+2));
  for(i=0;i<=P->Dimension;i++) {
    value_init(p[i]);
    value_set_si(p[i],0);
  }
  value_init(p[i]);
  value_set_si(p[i],1);
  
  /*** S = scanning list of polyhedra ***/
  S = Polyhedron_Scan(P,C,MAXRAYS);

  value_init(c);
  
  /******* Count now *********/
  FOREVER {
    fflush(stdin);
    printf("Enter %d parameters : ",C->Dimension);
    for(k=S->Dimension-C->Dimension+1;k<=S->Dimension;++k) {
      scanf(" %s", str);
      value_read(p[k],str);
    }      
    printf("EP( ");
    value_print(stdout,VALUE_FMT,p[S->Dimension-C->Dimension+1]);
    for(k=S->Dimension-C->Dimension+2;k<=S->Dimension;++k) {
      printf(", ");
      value_print(stdout,VALUE_FMT,p[k]);
    }  
    printf(" ) = "); 
    count_points(1,S,p,&c);
    value_print(stdout,VALUE_FMT,c);
    printf("\n"); 
  }
  for(i=0;i<=(P->Dimension+1);i++)
    value_clear(p[i]);
  value_clear(c);
  return(0);
} /* main */