int main()
{
    vtx **P;
    vtx *gd;
    vtx *S;
    double hmin;

    P = (vtx**)malloc(3 * sizeof(vtx*));
    gd = (vtx*)malloc(sizeof(vtx));
    S = (vtx*)malloc(sizeof(vtx));

    *(P + 0) = initialize_vertex(*(P + 0));
    *(P + 1) = initialize_vertex(*(P + 1));
    *(P + 2) = initialize_vertex(*(P + 2));
    gd = initialize_vertex(gd);
    S = initialize_vertex(S);

    (*(P + 0))->coord_x = -3;
    (*(P + 0))->coord_y = -2;

    do{
        gd = gradient(*(P + 0),gd);
        S = compute_S(gd, S);

        //show_vertex(gd);
        //show_vertex(S);
        hmin = compute_min(*(P + 0), S);
        printf("%.8lf\\\\\\hline\n",hmin);
        (*(P + 1))->coord_x = (*(P+0))->coord_x;
        (*(P + 1))->coord_y = (*(P+0))->coord_y;
        (*(P + 0))->coord_x = (*(P+0))->coord_x + hmin * S->coord_x;
        (*(P + 0))->coord_y = (*(P+0))->coord_y + hmin * S->coord_y;
    }while(distance(*(P + 0), *(P + 1)) > 1e-7);



    return 0;
}
Beispiel #2
0
std::string process_mesh(const aiMesh* mesh, const aiScene* scene, 
						std::unordered_map<std::string, GLuint>& bone_id_map,
						const std::string& modelname){
	std::vector<Vertex> vertices;
	std::vector<GLuint> indices;
	std::string material_name;

	vertices.resize(mesh->mNumVertices);

	for(GLuint i = 0; i < mesh->mNumVertices; ++i) {
		Vertex vertex;
		initialize_vertex(vertex);

		glm::vec3 pos_vector;
		pos_vector.x = mesh->mVertices[i].x;
		pos_vector.y = mesh->mVertices[i].y;
		pos_vector.z = mesh->mVertices[i].z;
		vertex.position = pos_vector;

		if (mesh->mNormals) {
			glm::vec3 norm_vector;
			norm_vector.x = mesh->mNormals[i].x;
			norm_vector.y = mesh->mNormals[i].y;
			norm_vector.z = mesh->mNormals[i].z;
			vertex.normal = norm_vector;
		}

		if(mesh->mTextureCoords[0]) {
			glm::vec2 tex_vector;
			tex_vector.x = mesh->mTextureCoords[0][i].x; 
			tex_vector.y = mesh->mTextureCoords[0][i].y;
			vertex.tex_coords = tex_vector;
		}

		vertices[i] = vertex;
	}
	
	for(GLuint i = 0; i < mesh->mNumFaces; i++) {
		aiFace face = mesh->mFaces[i];

		for(GLuint j = 0; j < face.mNumIndices; j++) {
			indices.push_back(face.mIndices[j]);
		}
	}

	std::string meshname = mesh->mName.data;
	if (!store_binary_material(scene, mesh, material_name)){
		std::cout << __FILE__ << ":" << __LINE__ << ": " << "WARNING: Failed to store binary material!" << std::endl;
		errorlogger("WARNING: Failed to store binary material!");
	}

	if (scene->HasAnimations()){
		std::unordered_map<GLuint, GLuint> bone_map;
		std::vector<glm::mat4> bone_info;
		load_mesh_bones(mesh, bone_map, bone_id_map, vertices, bone_info);
		store_binary_mesh(scene, vertices, indices, material_name, meshname, modelname, bone_map, bone_info);
	}
	else{
		store_binary_mesh(vertices, indices, material_name, meshname, modelname);
	}

	return meshname;
}
  void finish_vertex(VertexDescriptorType v, VertexDescriptorType sourceNode, TGraph& g)
  {
    // Construct the region around the vertex
    itk::Index<2> indexToFinish;
    indexToFinish[0] = v[0];
    indexToFinish[1] = v[1];

    itk::ImageRegion<2> region = ITKHelpers::GetRegionInRadiusAroundPixel(indexToFinish, HalfWidth);

    region.Crop(Image->GetLargestPossibleRegion()); // Make sure the region is entirely inside the image

    // Mark all the pixels in this region as filled.
    // It does not matter which image we iterate over, we just want the indices.
    itk::ImageRegionConstIteratorWithIndex<TImage> gridIterator(Image, region);

    while(!gridIterator.IsAtEnd())
    {
      VertexDescriptorType v;
      v[0] = gridIterator.GetIndex()[0];
      v[1] = gridIterator.GetIndex()[1];
      put(FillStatusMap, v, true);
      MaskImage->SetPixel(gridIterator.GetIndex(), MaskImage->GetValidValue());
      ++gridIterator;
    }

    // Additionally, initialize the filled vertices because they may now be valid.
    // This must be done in a separate loop like this because the mask image used to check for boundary pixels is incorrect until the above loop updates it.
    gridIterator.GoToBegin();
    while(!gridIterator.IsAtEnd())
    {
      VertexDescriptorType v;
      v[0] = gridIterator.GetIndex()[0];
      v[1] = gridIterator.GetIndex()[1];
      initialize_vertex(v, g);
      ++gridIterator;
    }

    // Update the priority function.
    this->PriorityFunction->Update(sourceNode, v);

    // Add pixels that are on the new boundary to the queue, and mark other pixels as not in the queue.
    itk::ImageRegionConstIteratorWithIndex<Mask> imageIterator(this->MaskImage, region);

    while(!imageIterator.IsAtEnd())
    {
      VertexDescriptorType v;
      v[0] = imageIterator.GetIndex()[0];
      v[1] = imageIterator.GetIndex()[1];

      // Mark all nodes in the patch around this node as filled (in the FillStatusMap).
      // This makes them ignored if they are still in the boundaryNodeQueue.
      if(ITKHelpers::HasNeighborWithValue(imageIterator.GetIndex(), this->MaskImage, this->MaskImage->GetHoleValue()))
      {
        put(BoundaryStatusMap, v, true);
        this->BoundaryNodeQueue.push(v);
        float priority = this->PriorityFunction->ComputePriority(imageIterator.GetIndex());
        //std::cout << "updated priority: " << priority << std::endl;
        put(this->PriorityMap, v, priority);
      }
      else
      {
        put(this->BoundaryStatusMap, v, false);
      }

      ++imageIterator;
    }

    {
    // Debug only - write the mask to a file
    HelpersOutput::WriteImage(this->MaskImage, Helpers::GetSequentialFileName("debugMask", this->NumberOfFinishedVertices, "png"));
    HelpersOutput::WriteVectorImageAsRGB(this->Image, Helpers::GetSequentialFileName("output", this->NumberOfFinishedVertices, "png"));
    this->NumberOfFinishedVertices++;
    }
  } // finish_vertex