Skip to content

Commit

Permalink
CPlot: corr. stereo for 360
Browse files Browse the repository at this point in the history
  • Loading branch information
benoit128 committed Oct 16, 2024
1 parent 0732582 commit b11bb50
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Cassiopee/CPlot/CPlot/Display/displayUSolid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void DataDL::displayUSolid()
// if zone is active and in frustum
if ((zonep->active == 1 ||
(zonep->active == 0 && ptrState->ghostifyDeactivatedZones == 1)) &&
isInFrustum( zonep, _view ) == 1 )
isInFrustum(zonep, _view) == 1)
{
if (ptrState->mode == RENDER && zonep->meshOverlay == 1)
{
Expand Down
119 changes: 85 additions & 34 deletions Cassiopee/CPlot/CPlot/PyTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,7 @@ def loadImageFiles(t, offscreen=0):

#==============================================================================
# subfunction of display 360. Display 6 views rotating over posCam.
#==============================================================================
def display360__(t, posCam, posEye, dirCam, offscreen, exportRez, kwargs):
import KCore.Vector as Vector

Expand Down Expand Up @@ -1190,7 +1191,7 @@ def display360WS__(t, posCam, posEye, dirCam, offscreen, exportRez, stereoShift,
# Compute all front view vectors
v1 = Vector.sub(posEye, posCam) # view vector
vz = Vector.normalize(dirCam) # third view vector
v2 = Vector.cross(vz, v1) # second view vector
v2 = Vector.cross(v1, vz) # second view vector
v2 = Vector.normalize(v2)

import Geom.PyTree as D
Expand Down Expand Up @@ -1221,10 +1222,10 @@ def display360WS__(t, posCam, posEye, dirCam, offscreen, exportRez, stereoShift,

# top image
point = D.point(v1p)
point = T.rotate(point, (0,0,0), v2p, -90)
point = T.rotate(point, (0,0,0), v2p, +90)
v1z = C.getValue(point, 'GridCoordinates', 0)
point = D.point(dirCam)
point = T.rotate(point, (0,0,0), v2p, -90)
point = T.rotate(point, (0,0,0), v2p, +90)
v2z = C.getValue(point, 'GridCoordinates', 0)

posEye0 = Vector.add(v1z, posCam)
Expand All @@ -1241,10 +1242,10 @@ def display360WS__(t, posCam, posEye, dirCam, offscreen, exportRez, stereoShift,

# bottom image
point = D.point(v1p)
point = T.rotate(point, (0,0,0), v2p, 90)
point = T.rotate(point, (0,0,0), v2p, -90)
v1z = C.getValue(point, 'GridCoordinates', 0)
point = D.point(dirCam)
point = T.rotate(point, (0,0,0), v2p, 90)
point = T.rotate(point, (0,0,0), v2p, -90)
v2z = C.getValue(point, 'GridCoordinates', 0)

posEye0 = Vector.add(v1z, posCam)
Expand Down Expand Up @@ -1352,7 +1353,7 @@ def display360ODS__(t, posCam, posEye, dirCam, offscreen, exportRez, stereoShift
# Compute all front view vectors
v1 = Vector.sub(posEye, posCam) # view vector
vz = Vector.normalize(dirCam) # third view vector
v2 = Vector.cross(vz, v1) # second view vector
v2 = Vector.cross(v1, vz) # second view vector
v2 = Vector.normalize(v2)

import Geom.PyTree as D
Expand Down Expand Up @@ -1391,10 +1392,10 @@ def display360ODS__(t, posCam, posEye, dirCam, offscreen, exportRez, stereoShift

# top image
point = D.point(v1p)
point = T.rotate(point, (0,0,0), v2p, -90)
point = T.rotate(point, (0,0,0), v2p, +90)
v1z = C.getValue(point, 'GridCoordinates', 0)
point = D.point(dirCam)
point = T.rotate(point, (0,0,0), v2p, -90)
point = T.rotate(point, (0,0,0), v2p, +90)
v2z = C.getValue(point, 'GridCoordinates', 0)

posEye0 = Vector.add(v1z, posCam)
Expand All @@ -1412,10 +1413,10 @@ def display360ODS__(t, posCam, posEye, dirCam, offscreen, exportRez, stereoShift

# bottom image
point = D.point(v1p)
point = T.rotate(point, (0,0,0), v2p, 90)
point = T.rotate(point, (0,0,0), v2p, -90)
v1z = C.getValue(point, 'GridCoordinates', 0)
point = D.point(dirCam)
point = T.rotate(point, (0,0,0), v2p, 90)
point = T.rotate(point, (0,0,0), v2p, -90)
v2z = C.getValue(point, 'GridCoordinates', 0)

posEye0 = Vector.add(v1z, posCam)
Expand All @@ -1438,7 +1439,6 @@ def display360ODS__(t, posCam, posEye, dirCam, offscreen, exportRez, stereoShift
# tentative only for osmesa
def display360ODS2__(t, posCam, posEye, dirCam, offscreen, exportRez, stereoShift, kwargs):

import Converter.Mpi as Cmpi
import KCore.Vector as Vector
lkwargs = kwargs.copy()

Expand All @@ -1462,7 +1462,7 @@ def display360ODS2__(t, posCam, posEye, dirCam, offscreen, exportRez, stereoShif
# Compute all front view vectors
v1 = Vector.sub(posEye, posCam) # view vector
vz = Vector.normalize(dirCam) # third view vector
v2 = Vector.cross(vz, v1) # second view vector
v2 = Vector.cross(v1, vz) # second view vector
v2 = Vector.normalize(v2)

import Geom.PyTree as D
Expand Down Expand Up @@ -1493,10 +1493,10 @@ def display360ODS2__(t, posCam, posEye, dirCam, offscreen, exportRez, stereoShif

# top image
point = D.point(v1p)
point = T.rotate(point, (0,0,0), v2p, -90)
point = T.rotate(point, (0,0,0), v2p, +90)
v1z = C.getValue(point, 'GridCoordinates', 0)
point = D.point(dirCam)
point = T.rotate(point, (0,0,0), v2p, -90)
point = T.rotate(point, (0,0,0), v2p, +90)
v2z = C.getValue(point, 'GridCoordinates', 0)

posEye0 = Vector.add(v1z, posCam)
Expand All @@ -1509,10 +1509,10 @@ def display360ODS2__(t, posCam, posEye, dirCam, offscreen, exportRez, stereoShif

# bottom image
point = D.point(v1p)
point = T.rotate(point, (0,0,0), v2p, 90)
point = T.rotate(point, (0,0,0), v2p, -90)
v1z = C.getValue(point, 'GridCoordinates', 0)
point = D.point(dirCam)
point = T.rotate(point, (0,0,0), v2p, 90)
point = T.rotate(point, (0,0,0), v2p, -90)
v2z = C.getValue(point, 'GridCoordinates', 0)

posEye0 = Vector.add(v1z, posCam)
Expand Down Expand Up @@ -1549,7 +1549,7 @@ def display360(t, type360=0, **kwargs):
offscreen = kwargs.get("offscreen", 1)
stereo = kwargs.get("stereo", 0)
stereoDist = kwargs.get("stereoDist", 0.07) # stereoDist is in real world distance
if stereo == 1: kwargs['stereo'] = 0
kwargs['stereo'] = 0 # force no anaglyph

# orthogonalisation de v1 et dirCam si ils ne sont pas orthos
v1 = Vector.sub(posEye, posCam) # view vector
Expand All @@ -1567,9 +1567,9 @@ def display360(t, type360=0, **kwargs):
panorama(export, exportRez, type360=type360)
Cmpi.barrier() # wait for completion

elif stereo == 1: # stereo (ODS)
elif stereo == 1: # stereo ODS internal (only offscreen=1 or 7)

if offscreen == 2: raise ValueError("display360: stereo=1 only for osmesa."); return None
if offscreen != 1 and offscreen != 7: raise ValueError("display360: stereo=1 only for osmesa."); return None

export1 = export.rsplit('.', 1)
if len(export1) == 2: export1 = export1[0]+'_1.'+export1[1]
Expand All @@ -1581,30 +1581,18 @@ def display360(t, type360=0, **kwargs):
# right eye
#stereoDist = 0. # forced to 0 for debug
kwargs['export'] = export1
if offscreen == 2:
display360ODS__(t, posCam, posEye, dirCam, offscreen, exportRez, stereoDist/2., kwargs)
if Cmpi.rank == 0:
panoramaODS(export1, exportRez, type360=type360)
Cmpi.barrier() # wait for completion
else:
display360ODS2__(t, posCam, posEye, dirCam, offscreen, exportRez, stereoDist/2., kwargs)
display360ODS2__(t, posCam, posEye, dirCam, offscreen, exportRez, stereoDist/2., kwargs)

# left eye
kwargs['export'] = export2
if offscreen == 2:
display360ODS__(t, posCam, posEye, dirCam, offscreen, exportRez, -stereoDist/2., kwargs)
if Cmpi.rank == 0:
panoramaODS(export2, exportRez, type360=type360)
Cmpi.barrier() # wait for completion
else:
display360ODS2__(t, posCam, posEye, dirCam, offscreen, exportRez, -stereoDist/2., kwargs)
display360ODS2__(t, posCam, posEye, dirCam, offscreen, exportRez, -stereoDist/2., kwargs)

# stitch
if Cmpi.rank == 0:
panoramaStereo(export, export1, export2, exportRez, type360=type360)
Cmpi.barrier() # wait for completion

else: # stereo = 2 (wrong stereo)
elif stereo == 2: # stereo = 2 (wrong stereo)
export1 = export.rsplit('.', 1)
if len(export1) == 2: export1 = export1[0]+'_1.'+export1[1]
else: export1 = export+'_1'
Expand All @@ -1629,6 +1617,68 @@ def display360(t, type360=0, **kwargs):
panoramaStereo(export, export1, export2, exportRez, type360=type360)
Cmpi.barrier() # wait for completion

elif stereo == 3: # stereo = 3 (wrong stereo 2)
export1 = export.rsplit('.', 1)
if len(export1) == 2: export1 = export1[0]+'_1.'+export1[1]
else: export1 = export+'_1'
export2 = export.rsplit('.', 1)
if len(export2) == 2: export2 = export2[0]+'_2.'+export2[1]
else: export2 = export+'_2'

v1 = Vector.sub(posEye, posCam) # view vector
vz = Vector.normalize(dirCam) # third view vector
v2 = Vector.cross(v1, vz) # second view vector
v2 = Vector.normalize(v2)
dv = Vector.mul(stereoDist/2, v2)

# right eye
posCam0 = Vector.add(posCam, dv)
display360__(t, posCam0, posEye, dirCam, offscreen, exportRez, kwargs)
if Cmpi.rank == 0:
panorama(export1, exportRez, type360=type360)
Cmpi.barrier() # wait for completion

# left eye
posCam0 = Vector.sub(posCam, dv)
display360__(t, posCam0, posEye, dirCam, offscreen, exportRez, kwargs)
if Cmpi.rank == 0:
panorama(export2, exportRez, type360=type360)
Cmpi.barrier() # wait for completion

# stitch
if Cmpi.rank == 0:
panoramaStereo(export, export1, export2, exportRez, type360=type360)
Cmpi.barrier() # wait for completion

elif stereo == 4: # stereo ODS external

export1 = export.rsplit('.', 1)
if len(export1) == 2: export1 = export1[0]+'_1.'+export1[1]
else: export1 = export+'_1'
export2 = export.rsplit('.', 1)
if len(export2) == 2: export2 = export2[0]+'_2.'+export2[1]
else: export2 = export+'_2'

# right eye
#stereoDist = 0. # forced to 0 for debug
kwargs['export'] = export1
display360ODS__(t, posCam, posEye, dirCam, offscreen, exportRez, stereoDist/2., kwargs)
if Cmpi.rank == 0:
panoramaODS(export1, exportRez, type360=type360)
Cmpi.barrier() # wait for completion

# left eye
kwargs['export'] = export2
display360ODS__(t, posCam, posEye, dirCam, offscreen, exportRez, -stereoDist/2., kwargs)
if Cmpi.rank == 0:
panoramaODS(export2, exportRez, type360=type360)
Cmpi.barrier() # wait for completion

# stitch
if Cmpi.rank == 0:
panoramaStereo(export, export1, export2, exportRez, type360=type360)
Cmpi.barrier() # wait for completion

return None

# assemble 6 cube images en une image panoramique
Expand Down Expand Up @@ -1659,6 +1709,7 @@ def panorama(export, exportRez, type360=0):
return a7

# assemble 2 images panoramiques en une image panoramique stereo
# export1: right, export2: left
def panoramaStereo(export, export1, export2, exportRez, type360=0):
import Generator.PyTree as G
# assemble 2 panoramic images in a single stereo image
Expand Down
4 changes: 4 additions & 0 deletions Cassiopee/CPlot/CPlot/displayNew.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ PyObject* K_CPLOT::displayNew(PyObject* self, PyObject* args)
d->ptrState->shootScreen = 0;
gdisplay(); // build DL

// print current renderer
const char* renderer = (const char*)glGetString(GL_RENDERER);
printf("Renderer: %s\n", renderer);

if (posCamList == Py_None)
{
//if (d->ptrState->stereo == 0) d->display();
Expand Down

0 comments on commit b11bb50

Please sign in to comment.