Skip to content

Commit

Permalink
CPlot: add type360 to display360
Browse files Browse the repository at this point in the history
benoit128 committed Jul 1, 2024
1 parent a45b8c8 commit abc981f
Showing 3 changed files with 18 additions and 12 deletions.
11 changes: 6 additions & 5 deletions Cassiopee/CPlot/CPlot/PyTree.py
Original file line number Diff line number Diff line change
@@ -1132,7 +1132,7 @@ def display360__(t, posCam, posEye, dirCam, offscreen, locRez, kwargs):
#==============================================================================
# display360 (offscreen=1, 2 or 7)
#==============================================================================
def display360(t, **kwargs):
def display360(t, type360=0, **kwargs):
"""Display for 360 images."""
import KCore.Vector as Vector
posCam = kwargs.get("posCam", (0,0,0))
@@ -1166,7 +1166,7 @@ def display360(t, **kwargs):
#display(a, panorama=1,
# offscreen=foffscreen, export=export, exportResolution=exportRez)
#finalizeExport(foffscreen)
panorama(export, exportRez)
panorama(export, exportRez, type360=type360)
Cmpi.barrier() # wait for completion

if stereo == 1: # left eye
@@ -1190,7 +1190,7 @@ def display360(t, **kwargs):
#display(a, panorama=1,
# offscreen=foffscreen, export=export2, exportResolution=exportRez)
#finalizeExport(foffscreen)
panorama(export, exportRez)
panorama(export2, exportRez, type360=type360)

# assemble images
a1 = C.convertFile2PyTree(export)
@@ -1212,7 +1212,8 @@ def display360(t, **kwargs):
Cmpi.barrier() # wait for completion
return None

def panorama(export, exportResolution):
# type360=0 -> 360, mode=1 -> 180
def panorama(export, exportResolution, type360=0):
res = exportResolution.split('x')
resx = int(res[0]); resy = int(res[1])
import Generator.PyTree as G
@@ -1232,6 +1233,6 @@ def panorama(export, exportResolution):
a7 = G.cart((0,0,0), (1,1,1), (resx, resy,1))
C._addVars(a7, ['r','g','b','a'])
a7f = C.getFields('nodes', a7, api=3)[0]
CPlot.cplot.panorama(a1, a2, a3, a4, a5, a6, a7f)
CPlot.cplot.panorama(a1, a2, a3, a4, a5, a6, a7f, type360)
C.convertPyTree2File(a7, export)
return a7
16 changes: 10 additions & 6 deletions Cassiopee/CPlot/CPlot/panorama.cpp
Original file line number Diff line number Diff line change
@@ -46,15 +46,18 @@ void interp(E_Int ind,

// perform the stitching (identical to panorama.frag but on the cpu)
// it doesnt have the texture size limit
// si type360=0 -> 360 deg
// si type360=1 -> 180 deg
PyObject* K_CPLOT::panorama(PyObject* self, PyObject* args)
{
// Get the 4 arrays of cube images (left, right, bottom, top, back, front)
PyObject* leftArray; PyObject* rightArray;
PyObject* bottomArray; PyObject* topArray;
PyObject* backArray; PyObject* frontArray;
PyObject* finalArray;
if (!PyArg_ParseTuple(args, "OOOOOOO", &leftArray, &rightArray,
&bottomArray, &topArray, &backArray, &frontArray, &finalArray))
E_Int type360;
if (!PYPARSETUPLE_(args, OOOO_ OOO_ I_, &leftArray, &rightArray,
&bottomArray, &topArray, &backArray, &frontArray, &finalArray, &type360))
{
return NULL;
}
@@ -124,7 +127,6 @@ PyObject* K_CPLOT::panorama(PyObject* self, PyObject* args)
E_Int nil, njl, nkl;
res = K_ARRAY::getFromArray3(finalArray, varString, final,
nil, njl, nkl, cn, eltType);
printf("varstring final=%s\n", varString);
if (res != 1)
{
PyErr_SetString(PyExc_TypeError,
@@ -136,7 +138,6 @@ PyObject* K_CPLOT::panorama(PyObject* self, PyObject* args)
#define M_PI 3.1415926535897932384626433832795

E_Int nijl = nil*njl;
printf("nijl=%d\n", nijl);
E_Int nil1 = nil-1;
E_Int njl1 = njl-1;
E_Int ni1 = ni-1;
@@ -176,7 +177,10 @@ PyObject* K_CPLOT::panorama(PyObject* self, PyObject* args)
E_Float* final2 = final->begin(5);
E_Float* final3 = final->begin(6);
E_Float* final4 = final->begin(7);

E_Float tinf, tsup;
if (type360 == 0) { tinf = -M_PI; tsup = 2*M_PI; } // 360
else { tinf = -M_PI/2.; tsup = M_PI; } // 180

#pragma omp parallel
{
E_Int ii, jj;
@@ -191,7 +195,7 @@ PyObject* K_CPLOT::panorama(PyObject* self, PyObject* args)
tx = (1.*ii) / nil1;
ty = (1.*jj) / njl1;

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

x = cos(phi) * sin(theta);
3 changes: 2 additions & 1 deletion Cassiopee/CPlot/test/display360sPT.py
Original file line number Diff line number Diff line change
@@ -16,5 +16,6 @@
posCam = (0,0,0); posEye = (1,0,0); dirCam = (0,0,1)

CPlot.display360(a, mode="Mesh", posCam=posCam, posEye=posEye, dirCam=dirCam,
offscreen=offscreen, stereo=1, stereoDist=0.1,
offscreen=offscreen, type360=0,
stereo=1, stereoDist=0.1,
export='image360.png', exportResolution='4096x2048')

0 comments on commit abc981f

Please sign in to comment.