How to add texture information in "ccSphere" class?
How to add texture information in "ccSphere" class?
Hello! I am a novice, I want to a picture of the aspect ratio of 2:1 to "ccSphere" class structure, according to the sphere of the medial do fake "ccPlane" class, add a "setAsTexture" method, why stick texture are displayed in the sphere of the outside rather than inside, thank you!
Re: How to add texture information in "ccSphere" class?
Can you clarify your question? It's hard to understand...
Daniel, CloudCompare admin
Re: How to add texture information in "ccSphere" class?
I am sorry,it is that I want to add texture in "ccSphere" class,now i add a "setAsTexture" function in "ccSphere" class like "ccPlane" class, anddaniel wrote:Can you clarify your question? It's hard to understand...
rewrite the" buildUp" function. The question is that the texture is show abnormal and displayed in the sphere of the outside rather than inside.
The code is:
Code: Select all
// Build up.
bool ccSphere::PanoBuildUp()
{
//[1]vertices
unsigned count = (g_iCol+1)*(g_iRow+1);
//[2]faces
unsigned faces = g_iCol*g_iRow*2;
if (!init(count,true,faces,0))
{
ccLog::Error("[ccSphere::buildUp] Not enough memory");
return false;
}
//[3] Initialize the ball coordinate matrix
float SpherePt[g_iCol+1][g_iRow+1][3];
int step_t = 360/g_iCol;
int step_f = 180/g_iRow;
for(int theta=0;theta<=360;theta+=step_t)
{
for( int fai=180;fai>=0;fai-=step_f)
{
SpherePt[theta/step_t][(180-fai)/step_f][0]=cos((float)theta/180.0*M_PI)*sin((float)fai/180.0*M_PI)*2;
SpherePt[theta/step_t][(180-fai)/step_f][1]=cos((float)fai/180.0*M_PI)*2;
SpherePt[theta/step_t][(180-fai)/step_f][2]=sin((float)fai/180.0*M_PI)*sin((float)theta/180.0*M_PI)*2;
}
}
//[4]vertices
{
ccPointCloud* verts = vertices();
assert(verts);
CCVector3 N,P;
for(int i=0; i<=g_iCol; ++i)
{
for (int j=0; j<=g_iRow; ++j)
{
N.x = SpherePt[i][j][0];
N.y = SpherePt[i][j][1];
N.z = SpherePt[i][j][2];
verts->addNorm(N);
P = N*m_radius;
verts->addPoint(P);
}
}
}
//
//[5]faces
{
assert(m_triVertIndexes);
for (int i=0; i<g_iCol; ++i)
{
for (int j=0; j<g_iRow; ++j)
{
unsigned A,B,C,D;
A = i*(g_iRow+1)+j; // Lower left corner
B = i*(g_iRow+1)+j+1; // The upper left corner
C = (i+1)*(g_iRow+1)+j+1; // Upper right corner
D = (i+1)*(g_iRow+1)+j; // Bottom right corner
addTriangle(A, C, B);
addTriangle(A, D, C);
}
}
}
notifyGeometryUpdate();
showNormals(true);
return true;
}
Code: Select all
// load image texture.
bool ccSphere::setAsTexture(const QImage& image)
{
if (image.isNull())
{
ccLog::Warning("[ccSphere::setAsTexture] Invalid texture image!");
return false;
}
//texture coordinates
TextureCoordsContainer* texCoords = getTexCoordinatesTable();
if (!texCoords)
{
texCoords = new TextureCoordsContainer();
if (!texCoords->reserve(g_iCol*g_iRow*4))
{
//not enough memory
ccLog::Warning("[ccSphere::setAsTexture] Not enough memory!");
delete texCoords;
return false;
}
//[2] Texture image coordinate matrix
float ImagePt[g_iCol+1][g_iRow+1][2];
for(int i=0;i<(g_iCol+1);i++)
{
for(int j=0;j<(g_iRow+1);j++)
{
ImagePt[i][j][0]= (float)i/g_iCol; // X
ImagePt[i][j][1]= (float)j/g_iRow; // Y
}
}
//create default texture coordinates
float TA[2] = { 0.0f, 0.0f };
float TB[2] = { 0.0f, 1.0f };
float TC[2] = { 1.0f, 1.0f };
float TD[2] = { 1.0f, 0.0f };
for (int i=0;i<g_iCol;++i)
{
for (int j=0;j<g_iRow;++j)
{
// Lower left corner
TA[0]=ImagePt[i][j][0];
TA[1]=ImagePt[i][j][1];
// The upper left corner
TB[0]=ImagePt[i][j][0];
TB[1]=ImagePt[i][j+1][1];
// Upper right corner
TC[0]=ImagePt[i+1][j+1][0];
TC[1]=ImagePt[i+1][j+1][1];
// Bottom right corner
TD[0]=ImagePt[i+1][j][0];
TD[1]=ImagePt[i][j][1];
texCoords->addElement(TA);
texCoords->addElement(TC);
texCoords->addElement(TB);
texCoords->addElement(TD);
}
}
setTexCoordinatesTable(texCoords);
}
if (!hasPerTriangleTexCoordIndexes())
{
if (!reservePerTriangleTexCoordIndexes())
{
//not enough memory
ccLog::Warning("[ccPlane::setAsTexture] Not enough memory!");
setTexCoordinatesTable(0);
removePerTriangleMtlIndexes();
return false;
}
//[3] set default texture indexes.
for (int i=0; i<g_iCol; ++i)
{
for (int j=0; j<g_iRow; ++j)
{
unsigned A,B,C,D;
A = i*(g_iRow)+j; // Lower left corner
B = i*(g_iRow)+j+1; // The upper left corner
C = (i+1)*(g_iRow)+j+1; // Upper right corner
D = (i+1)*(g_iRow)+j; // Bottom right corner
addTriangleTexCoordIndexes(A, C, B);
addTriangleTexCoordIndexes(A, D, C);
}
}
}
if (!hasPerTriangleMtlIndexes())
{
if (!reservePerTriangleMtlIndexes())
{
//not enough memory
ccLog::Warning("[ccPlane::setAsTexture] Not enough memory!");
setTexCoordinatesTable(0);
removePerTriangleTexCoordIndexes();
return false;
}
//[3] set default material indexes
for (int i=0; i<g_iCol; ++i)
{
for (int j=0; j<g_iRow; ++j)
{
addTriangleMtlIndex(0);
addTriangleMtlIndex(0);
}
}
}
//set material
if (!getMaterialSet())
setMaterialSet(new ccMaterialSet());
ccMaterialSet* materialSet = const_cast<ccMaterialSet*>(getMaterialSet());
assert(materialSet);
//remove old material (if any)
materialSet->clear();
//add new material
{
ccMaterial::Shared material(new ccMaterial("texture"));
material->setTexture(image,QString(),false);
materialSet->addMaterial(material);
}
showMaterials(true);
return true;
}
Re: How to add texture information in "ccSphere" class?
The aspect ratio of the picture is 2: 1, just like the attach file:"image1.jpg".Thanks very much!daniel wrote:Can you clarify your question? It's hard to understand...
Re: How to add texture information in "ccSphere" class?
I can't see the image. It would be very helpful ;)
Daniel, CloudCompare admin
Re: How to add texture information in "ccSphere" class?
Oh, and can you show us a snapshot of the current result?
Daniel, CloudCompare admin
Re: How to add texture information in "ccSphere" class?
Ok! The snapshot of the current result like attach file "snapshot.jpg", I user "ccViewer" to display:daniel wrote:Oh, and can you show us a snapshot of the current result?
Besides the variable “g_iCol” and "g_iRow" is:
Code: Select all
const int g_iCol=90;//Setting the image many times do longitudinal split
const int g_iRow=45;//Setting the image many times do lateral split
Re: How to add texture information in "ccSphere" class?
Can't you see the image? I added it by the "Add files" button of "Attachement". ...daniel wrote:I can't see the image. It would be very helpful ;)
Re: How to add texture information in "ccSphere" class?
Can you see it?
Once you select it, check that the 'status' is a green check symbol. And just to be sure, click on 'place inline' (with the cursor at end of your message for instance).
Once you select it, check that the 'status' is a green check symbol. And just to be sure, click on 'place inline' (with the cursor at end of your message for instance).
Daniel, CloudCompare admin
Re: How to add texture information in "ccSphere" class?
"image1.jpg":daniel wrote:Oh, and can you show us a snapshot of the current result?
The snapshot of the result:
"snapshot.jpg"