Skip to content

Commit

Permalink
CPlot: corr. display 360
Browse files Browse the repository at this point in the history
  • Loading branch information
benoit128 committed Dec 2, 2024
1 parent 7903625 commit 5c02035
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 44 deletions.
13 changes: 8 additions & 5 deletions Cassiopee/CPlot/CPlot/Plugins/screenDump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,12 +409,12 @@ char* Data::export2Image(E_Int exportWidth, E_Int exportHeight)
offscreenD[ind] = depth[ind];
}
}
}
}
// export dans buffer
char* offscreen = (char*)ptrState->offscreenBuffer[ptrState->frameBuffer+1];
for (E_Int i = 0; i < screenSize*3; i++) buffer[i] = offscreen[i];
free(depth);
}
// export dans buffer
char* offscreen = (char*)ptrState->offscreenBuffer[ptrState->frameBuffer+1];
for (E_Int i = 0; i < screenSize*3; i++) buffer[i] = offscreen[i];
free(depth);
#else
printf("Error: CPlot: mesa offscreen unavailable.\n");
#endif
Expand All @@ -429,6 +429,9 @@ char* Data::export2Image(E_Int exportWidth, E_Int exportHeight)
glDeleteFramebuffersEXT(1, &fb);
#endif

// software postprocessing on final buffer (just before screen dump)


return buffer;
}

Expand Down
4 changes: 1 addition & 3 deletions Cassiopee/CPlot/CPlot/PyTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -1436,7 +1436,7 @@ def display360ODS__(t, posCam, posEye, dirCam, offscreen, exportRez, stereoShift
return None

# subfunction of display 360. Display the n views with rotating posCam
# tentative only for osmesa
# only for osmesa
def display360ODS2__(t, posCam, posEye, dirCam, offscreen, exportRez, stereoShift, kwargs):

import KCore.Vector as Vector
Expand Down Expand Up @@ -1730,8 +1730,6 @@ def panoramaStereo(export, export1, export2, exportRez, type360=0):
pr2 = Internal.getNodeFromName2(a2, v)
if pr1 is not None and pr2 is not None:
pr1 = pr1[1]; pr2 = pr2[1]
pr1 = pr1[:,::-1]
pr2 = pr2[:,::-1]
pr[0:ni,0:nj] = pr1[0:ni, 0:nj]
pr[0:ni,nj:2*nj] = pr2[0:ni, 0:nj]
else:
Expand Down
93 changes: 85 additions & 8 deletions Cassiopee/CPlot/CPlot/blur.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ void createGaussFilter(E_Float sigma, E_Int n, E_Float* c)
{
c[i] = exp( -(i*i) / (2.*sigma2)) / (sigma*sqrt(2.*M_PI));
}

/*
printf("gaussian coefficients: ");
for (E_Int i = 0; i <= n; i++) printf("%g ", c[i]);
printf("\n");
Expand All @@ -44,44 +46,119 @@ void createGaussFilter(E_Float sigma, E_Int n, E_Float* c)
sum += c[i];
}
printf("sum=%g\n", sum);
*/
}

// Apply gaussian blur to in
// Apply gaussian blur to in (single scalar)
// IN: in: color array
// IN: ni,nj: image size
// IN: c: kernel coef
// IN: n: kernel half size
// OUT: out: color array (already allocated)
void gaussianBlur2(E_Float* in, E_Int ni, E_Int nj, E_Float* c, E_Int n, E_Float* out)
{
E_Int ind;

// filter
for (E_Int j = 0; j < nj; j++)
for (E_Int i = 0; i < ni; i++)
{
ind = i+j*ni;
out[ind] = in[ind]*c[0];
}

// filter en i
for (E_Int j = 0; j < nj; j++)
for (E_Int i = n; i < ni-n; i++)
{
out[i+j*ni] = in[i+j*ni]*c[0];

ind = i+j*ni;
for (E_Int k = 1; k <= n; k++)
{
out[i+j*ni] += in[i-k+j*ni]*c[k]; // right
out[i+j*ni] += in[i+k+j*ni]*c[k]; // left
out[ind] += in[ind-k]*c[k]; // right
out[ind] += in[ind+k]*c[k]; // left
}
}

// filter en j
for (E_Int j = n; j < nj-n; j++)
for (E_Int i = 0; i < ni; i++)
{
ind = i+j*ni;
in[ind] = out[ind]*c[0];

for (E_Int k = 1; k <= n; k++)
{
out[ind] += in[ind-k*ni]*c[k];
out[ind] += in[ind+k*ni]*c[k];
}
}
}

// identical but applied to interlaced color buffer (3), return out
void gaussianBlur3(char* in, E_Int ni, E_Int nj, E_Float* c, E_Int n, float* depth, char* out)
{
float dmin, dmax;
// compute min/max of depth
dmin = 1.e30; dmax = -1.e30;
for (E_Int i = 0; i < ni*nj; i++)
{
dmin = std::min(dmin, depth[i]);
dmax = std::max(dmax, depth[i]);
}
// normalize depth
for (E_Int i = 0; i < ni*nj; i++)
{
depth[i] = (depth[i]-dmin)/(dmax-dmin);
}

// assombrit les pixels lointains
double percentage = 0.8;
for (E_Int i = 0; i < ni*nj; i++)
{
if (depth[i] > 0.5)
{
out[3*i] = in[3*i]*percentage;
out[3*i+1] = in[3*i+1]*percentage;
out[3*i+2] = in[3*i+2]*percentage;
}
}

// dof
/*
// blur en i
for (E_Int j = 0; j < nj; j++)
for (E_Int i = n; i < ni-n; i++)
{
ind = i+j*ni;
out[3*ind] = in[3*ind]*c[0];
out[3*ind+1] = in[3*ind+1]*c[0];
out[3*ind+2] = in[3*ind+2]*c[0];
for (E_Int k = 1; k <= n; k++)
{
out[ind] += in[i-k+j*ni]*c[k]; // right
out[ind] += in[i+k+j*ni]*c[k]; // left
}
}
// blur en j
for (E_Int j = n; j < nj-n; j++)
for (E_Int i = 0; i < ni; i++)
{
in[i+j*ni] = out[i+j*ni]*c[0];
for (E_Int k = 1; k <= n; k++)
{
in[i+j*ni] += out[i+(j-k)*ni]*c[k];
in[i+j*ni] += out[i+(j+k)*ni]*c[k];
out[i+j*ni] += in[i+(j-k)*ni]*c[k];
out[i+j*ni] += in[i+(j+k)*ni]*c[k];
}
}
*/
// antialiasing

}

// bllur array
// blur array
PyObject* K_CPLOT::blur(PyObject* self, PyObject* args)
{
// Get the 4 arrays of cube images (left, right, bottom, top, back, front)
Expand Down
4 changes: 2 additions & 2 deletions Cassiopee/CPlot/CPlot/panorama.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ PyObject* K_CPLOT::panorama(PyObject* self, PyObject* args)
ty = (1.*jj) / njl1;

theta = tinf + tx * tsup; // between -pi and pi
phi = M_PI/2. - ty * M_PI; // between pi/2 and -pi/2
phi = -M_PI/2. + ty * M_PI; // between pi/2 and -pi/2

x = cos(phi) * sin(theta);
y = sin(phi);
Expand Down Expand Up @@ -499,7 +499,7 @@ PyObject* K_CPLOT::panoramaODS(PyObject* self, PyObject* args)
for (E_Int j = 0; j < njl; j++)
{
ty = (1.*j)/nj1;
phi = M_PI/2. - ty * M_PI; // between pi/2 and -pi/2
phi = - M_PI/2. + ty * M_PI; // between pi/2 and -pi/2

ind = i + j*nil;

Expand Down
16 changes: 0 additions & 16 deletions Cassiopee/Envs/sh_Cassiopee_local
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ if echo "$KC" | grep -q 'celeste'; then export MAC="visio"; fi
if echo "$KC" | grep -q 'visung'; then export MAC="visung"; fi
if echo "$KC" | grep -q 'giulia'; then export MAC="giulia"; fi
if echo "$KC" | grep -q 'sator'; then export MAC="sator_cas"; fi
if echo "$KC" | grep -q 'jean-zay'; then export MAC="jean-zay"; fi
if echo "$KC" | grep -q 'spiro'; then export MAC="spiro_el8"; fi
if echo "$KC" | grep -q 'cobalt'; then export MAC="cobalt"; fi
if echo "$KC" | grep -q 'irene'; then export MAC="irene"; fi
Expand Down Expand Up @@ -742,21 +741,6 @@ elif [ "$MAC" = "sator_sph" ]; then
export PRODMODE=1
export PIP_DISABLE_PIP_VERSION_CHECK=1

elif [ "$MAC" = "jean-zay" ]; then
#-----------------------------jean-zay IDRIS ---------------------------------------
export ELSAPROD=jz_r8
export ELSAPROD=$ELSAPROD$EXT
# Nbre de threads
export OMP_NUM_THREADS=40
export KMP_AFFINITY="compact,1,0,granularity=fine,verbose"
# modules
#. /etc/profile.d/module.sh
module load intel-compilers/19.1.3
module load intel-mpi/2019.9
module load python/3.7.10
module load hdf5/1.12.0
export PYTHONEXE=python3

elif [ "$MAC" = "adastra_cpu" ]; then
#----------------------------- adastra cpu ---------------------------------------
export ELSAPROD=adastra_cpu
Expand Down
6 changes: 6 additions & 0 deletions Cassiopee/Initiator/Initiator/MeshSize.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ def meshSize(UInf, RoInf, ReInf, LInf, esurc=0.012, yplus=1., algo='Turbulent'):
else:
raise ValueError('meshSize: unknown algo.')

def boundaryLayerHeight(ReInf, algo='Turbulent'):
if algo == 'Laminar':
delta = 0.75*5*ReInf**(-0.5)
elif algo == 'Turbulent':
delta = 0.75*0.37*ReInf**(-1./5.)
return delta

if __name__ == '__main__':
print(meshSize1(1., 1.225, 0.000017894, 1.0))
Expand Down
41 changes: 31 additions & 10 deletions Cassiopee/OCC/OCC/Atomic/addLabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,38 @@
#include <TopExp_Explorer.hxx>
#include <TopAbs.hxx>

// Assuming you have a document and a shape
Handle(XCAFDoc_ShapeTool) shapeTool = XCAFDoc_DocumentTool::ShapeTool(myDocument->Main());
TopoDS_Shape myShape = ...; // Your shape

// Iterate over faces
for (TopExp_Explorer exp(myShape, TopAbs_FACE); exp.More(); exp.Next())
//=====================================================================
// Add label to shape
//=====================================================================
PyObject* K_OCC::addLabel(PyObject* self, PyObject* args)
{
TopoDS_Shape face = exp.Current();
TDF_Label label;
if (shapeTool->FindShape(face, label))
PyObject* hook;
if (!PYPARSETUPLE_(args, O, &hook)) return NULL;

void** packet = NULL;
#if (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 7) || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 1)
packet = (void**) PyCObject_AsVoidPtr(hook);
#else
packet = (void**) PyCapsule_GetPointer(hook, NULL);
#endif

//TopTools_IndexedMapOfShape& edges = *(TopTools_IndexedMapOfShape*)packet[2];
TopTools_IndexedMapOfShape& surfaces = *(TopTools_IndexedMapOfShape*)packet[1];

TopoDS_Shape* shp = (TopoDS_Shape*)packet[0];

// Assuming you have a document and a shape
Handle(XCAFDoc_ShapeTool) shapeTool = XCAFDoc_DocumentTool::ShapeTool(myDocument->Main());
TopoDS_Shape myShape = ...; // Your shape

// Iterate over faces
for (TopExp_Explorer exp(myShape, TopAbs_FACE); exp.More(); exp.Next())
{
// Do something with the label
TopoDS_Shape face = exp.Current();
TDF_Label label;
if (shapeTool->FindShape(face, label))
{
// Do something with the label
}
}
}

0 comments on commit 5c02035

Please sign in to comment.