Example #1
0
bool FilterMutualInfoPlugin::UpdateGraph(MeshDocument &md, SubGraph graph, int n)
{
	Solver solver;
	MutualInfo mutual;
	
	align.mesh=&md.mm()->cm;

	vcg::Point3f *vertices = new vcg::Point3f[align.mesh->vn];
	vcg::Point3f *normals = new vcg::Point3f[align.mesh->vn];
	vcg::Color4b *colors = new vcg::Color4b[align.mesh->vn];
	unsigned int *indices = new unsigned int[align.mesh->fn*3];

	for(int i = 0; i < align.mesh->vn; i++) {
	vertices[i] = align.mesh->vert[i].P();
	normals[i] = align.mesh->vert[i].N();
	colors[i] = align.mesh->vert[i].C();
	}

	for(int i = 0; i < align.mesh->fn; i++) 
	for(int k = 0; k < 3; k++) 
	indices[k+i*3] = align.mesh->face[i].V(k) - &*align.mesh->vert.begin();

	glBindBufferARB(GL_ARRAY_BUFFER_ARB, align.vbo);
	glBufferDataARB(GL_ARRAY_BUFFER_ARB, align.mesh->vn*sizeof(vcg::Point3f), 
	  vertices, GL_STATIC_DRAW_ARB);
	glBindBufferARB(GL_ARRAY_BUFFER_ARB, align.nbo);
	glBufferDataARB(GL_ARRAY_BUFFER_ARB, align.mesh->vn*sizeof(vcg::Point3f), 
	  normals, GL_STATIC_DRAW_ARB);
	glBindBufferARB(GL_ARRAY_BUFFER_ARB, align.cbo);
	glBufferDataARB(GL_ARRAY_BUFFER_ARB, align.mesh->vn*sizeof(vcg::Color4b), 
	  colors, GL_STATIC_DRAW_ARB);
	glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);

	glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, align.ibo);
	glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, align.mesh->fn*3*sizeof(unsigned int), 
	  indices, GL_STATIC_DRAW_ARB);
	glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);


	// it is safe to delete after copying data to VBO
	delete []vertices;
	delete []normals;
	delete []colors;
	delete []indices;
	
	for (int h=0; h<graph.nodes.size(); h++)
		for (int l=0; l<graph.nodes[h].arcs.size(); l++)
		{
			if(graph.nodes[h].arcs[l].imageId==n || graph.nodes[h].arcs[l].projId==n)
			{
//////////////////
				int imageId=graph.nodes[h].arcs[l].imageId;
				int imageProj=graph.nodes[h].arcs[l].projId;

				//this->glContext->makeCurrent();
				
				align.image=&md.rasterList[imageId]->currentPlane->image;
				align.shot=md.rasterList[imageId]->shot;

				//this->initGL();
				align.resize(800);

				

				//align.shot=par.getShotf("Shot");

				align.shot.Intrinsics.ViewportPx[0]=int((double)align.shot.Intrinsics.ViewportPx[1]*align.image->width()/align.image->height());
				align.shot.Intrinsics.CenterPx[0]=(int)(align.shot.Intrinsics.ViewportPx[0]/2);

				/*align.mode=AlignSet::COMBINE;
				align.renderScene(align.shot, 3, true);
				align.comb=align.rend;*/

				align.mode=AlignSet::PROJIMG;
				align.shotPro=md.rasterList[imageProj]->shot;
				align.imagePro=&md.rasterList[imageProj]->currentPlane->image;
				align.ProjectedImageChanged(*align.imagePro);
				float countTot=0.0;
				float countCol=0.0;
				align.RenderShadowMap();
				align.renderScene(align.shot, 1, true);
				//align.readRender(1);
				/*for (int x=0; x<align.wt; x++)
					for (int y=0; y<align.ht; y++)
					{
						QColor color;
						color.setRgb(align.comb.pixel(x,y));
						if (color!=qRgb(0,0,0))
						{
							countTot++;
							if (align.comb.pixel(x,y)!=align.rend.pixel(x,y))
								countCol++;
						}
					}
				graph.nodes[h].arcs[l].area=countCol/countTot;*/
				graph.nodes[h].arcs[l].mutual=mutual.info(align.wt,align.ht,align.target,align.render);
					
					
				//this->glContext->doneCurrent();

//////////////////////////77

			}
		}


	return true;

}
Example #2
0
std::vector<AlignPair> FilterMutualInfoPlugin::CalcPairs(MeshDocument &md, bool globalign)
{
	Solver solver;
	MutualInfo mutual;
	
	std::vector<AlignPair> list;

	align.mesh=&md.mm()->cm;
	
	/*solver.optimize_focal=true;
	solver.fine_alignment=true;*/

	{
		vcg::Point3f *vertices = new vcg::Point3f[align.mesh->vn];
		vcg::Point3f *normals = new vcg::Point3f[align.mesh->vn];
		vcg::Color4b *colors = new vcg::Color4b[align.mesh->vn];
		unsigned int *indices = new unsigned int[align.mesh->fn*3];

		for(int i = 0; i < align.mesh->vn; i++) {
			vertices[i] = align.mesh->vert[i].P();
			normals[i] = align.mesh->vert[i].N();
			colors[i] = align.mesh->vert[i].C();
		}

		for(int i = 0; i < align.mesh->fn; i++) 
		for(int k = 0; k < 3; k++) 
		indices[k+i*3] = align.mesh->face[i].V(k) - &*align.mesh->vert.begin();

		glBindBufferARB(GL_ARRAY_BUFFER_ARB, align.vbo);
		glBufferDataARB(GL_ARRAY_BUFFER_ARB, align.mesh->vn*sizeof(vcg::Point3f), 
				  vertices, GL_STATIC_DRAW_ARB);
		glBindBufferARB(GL_ARRAY_BUFFER_ARB, align.nbo);
		glBufferDataARB(GL_ARRAY_BUFFER_ARB, align.mesh->vn*sizeof(vcg::Point3f), 
				  normals, GL_STATIC_DRAW_ARB);
		glBindBufferARB(GL_ARRAY_BUFFER_ARB, align.cbo);
		glBufferDataARB(GL_ARRAY_BUFFER_ARB, align.mesh->vn*sizeof(vcg::Color4b), 
				  colors, GL_STATIC_DRAW_ARB);
		glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);

		glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, align.ibo);
		glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, align.mesh->fn*3*sizeof(unsigned int), 
				  indices, GL_STATIC_DRAW_ARB);
		glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);

		// it is safe to delete after copying data to VBO
		delete []vertices;
		delete []normals;
		delete []colors;
		delete []indices;
	}

	//align.mode=AlignSet::PROJIMG;
		
	//this->glContext->makeCurrent();
	for (int r=0; r<md.rasterList.size(); r++)
	{
		if(md.rasterList[r]->visible)
		{
			AlignPair pair;
			align.image=&md.rasterList[r]->currentPlane->image;
			align.shot=md.rasterList[r]->shot;

			//this->initGL();
			align.resize(800);

			//align.shot=par.getShotf("Shot");

			align.shot.Intrinsics.ViewportPx[0]=int((double)align.shot.Intrinsics.ViewportPx[1]*align.image->width()/align.image->height());
			align.shot.Intrinsics.CenterPx[0]=(int)(align.shot.Intrinsics.ViewportPx[0]/2);

			align.mode=AlignSet::COMBINE;
			align.renderScene(align.shot, 3, true);
			align.comb=align.rend;
			QImage covered=align.comb;
			std::vector<AlignPair> weightList;

			for (int p=0; p<md.rasterList.size(); p++)
			{
				if (p!=r)
				{
					align.mode=AlignSet::PROJIMG;
					align.shotPro=md.rasterList[p]->shot;
					align.imagePro=&md.rasterList[p]->currentPlane->image;
					align.ProjectedImageChanged(*align.imagePro);
					float countTot=0.0;
					float countCol=0.0;
					float countCov=0.0;
					align.RenderShadowMap();
					align.renderScene(align.shot, 2, true);
					//align.readRender(1);
					for (int x=0; x<align.wt; x++)
						for (int y=0; y<align.ht; y++)
						{
							QColor color;
							color.setRgb(align.comb.pixel(x,y));
							if (color!=qRgb(0,0,0))
							{
								countTot++;
								if (align.comb.pixel(x,y)!=align.rend.pixel(x,y))
								{
									countCol++;
								}
							}
						}
						pair.area=countCol/countTot;
											
						if (pair.area>0.2)
						{
							pair.mutual=mutual.info(align.wt,align.ht,align.target,align.render);
							pair.imageId=r;
							pair.projId=p;
							pair.weight=pair.area*pair.mutual;
							weightList.push_back(pair);

						}
				}
			}

			Log(0, "Image %d completed",r);
			if (!globalign)
			{
				for (int i=0; i<weightList.size(); i++)
				{
					Log(0, "Area %3.2f, Mutual %3.2f",weightList[i].area,weightList[i].mutual);
					list.push_back(weightList[i]);

				}

				//Log(0, "Tot arcs %d, Valid arcs %d",(md.rasterList.size())*(md.rasterList.size()-1),list.size());
				//return list;

			}
			else
			{


				std::sort(weightList.begin(), weightList.end(), orderingW());

				///////////////////////////////////////7
				for (int i=0; i<weightList.size(); i++)
				{
					int p=weightList[i].projId;
					align.mode=AlignSet::PROJIMG;
					align.shotPro=md.rasterList[p]->shot;
					align.imagePro=&md.rasterList[p]->currentPlane->image;
					align.ProjectedImageChanged(*align.imagePro);
					float countTot=0.0;
					float countCol=0.0;
					float countCov=0.0;
					align.RenderShadowMap();
					align.renderScene(align.shot, 2, true);
					//align.readRender(1);
					for (int x=0; x<align.wt; x++)
						for (int y=0; y<align.ht; y++)
						{
							QColor color;
							color.setRgb(align.comb.pixel(x,y));
							if (color!=qRgb(0,0,0))
							{
								countTot++;
								if (align.comb.pixel(x,y)!=align.rend.pixel(x,y))
								{
									if (covered.pixel(x,y)!=qRgb(255,0,0))
									{
										countCov++;
										covered.setPixel(x,y,qRgb(255,0,0));
									}
									countCol++;
								}
							}
						}
						pair.area=countCol/countTot;
						/*covered.save("covered.jpg");
						align.rend.save("rend.jpg");
						align.comb.save("comb.jpg");*/
						
						pair.area*=countCov/countTot;
						pair.mutual=mutual.info(align.wt,align.ht,align.target,align.render);
						pair.imageId=r;
						pair.projId=p;
						pair.weight=weightList[i].weight;
						list.push_back(pair);
						Log(0, "Area %3.2f, Mutual %3.2f",pair.area,pair.mutual);
					}
			}
			
		}
		}
//////////////////////////////////////////////////////

	

	Log(0, "Tot arcs %d, Valid arcs %d",(md.rasterList.size())*(md.rasterList.size()-1),list.size());
		
	
		//emit md.rasterSetChanged();
	//this->glContext->doneCurrent();
	return list;

}