"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "layer1/SceneRay.cpp" between
pymol-open-source-2.2.0.tar.gz and pymol-open-source-2.3.0.tar.gz

About: PyMOL is a Python-enhanced molecular graphics tool. It excels at 3D visualization of proteins, small molecules, density, surfaces, and trajectories. It also includes molecular editing, ray tracing, and movies. Open Source version.

SceneRay.cpp  (pymol-open-source-2.2.0):SceneRay.cpp  (pymol-open-source-2.3.0)
skipping to change at line 12 skipping to change at line 12
#include"Scene.h" #include"Scene.h"
#include"SceneRay.h" #include"SceneRay.h"
#include"SceneDef.h" #include"SceneDef.h"
#include"Util.h" #include"Util.h"
#include"ShaderMgr.h" #include"ShaderMgr.h"
#include"Matrix.h" #include"Matrix.h"
#include"PyMOL.h" #include"PyMOL.h"
#include"ListMacros.h" #include"ListMacros.h"
#include"Color.h" #include"Color.h"
#include"P.h" #include"P.h"
#ifdef _PYMOL_IP_EXTRAS #include"LangUtil.h"
#include "IncentiveCopyToClipboard.h"
#endif
static double accumTiming = 0.0; static double accumTiming = 0.0;
/* EXPERIMENTAL VOLUME RAYTRACING DATA */ /* EXPERIMENTAL VOLUME RAYTRACING DATA */
extern float *rayDepthPixels; extern float *rayDepthPixels;
extern int rayVolume, rayWidth, rayHeight; extern int rayVolume, rayWidth, rayHeight;
static void SceneRaySetRayView(PyMOLGlobals * G, CScene *I, int stereo_hand, static void SceneRaySetRayView(PyMOLGlobals * G, CScene *I, int stereo_hand,
float *rayView, float *angle, float shift) float *rayView, float *angle, float shift)
{ {
skipping to change at line 106 skipping to change at line 104
CRay *ray = NULL; CRay *ray = NULL;
float height, width; float height, width;
float aspRat; float aspRat;
float rayView[16]; float rayView[16];
double timing; double timing;
char *charVLA = NULL; char *charVLA = NULL;
char *headerVLA = NULL; char *headerVLA = NULL;
float fov; float fov;
int stereo_hand = 0; int stereo_hand = 0;
int grid_mode = SettingGetGlobal_i(G, cSetting_grid_mode); int grid_mode = SettingGetGlobal_i(G, cSetting_grid_mode);
ImageType *stereo_image = NULL; std::shared_ptr<pymol::Image> stereo_image;
OrthoLineType prefix = ""; OrthoLineType prefix = "";
int ortho = SettingGetGlobal_i(G, cSetting_ray_orthoscopic); int ortho = SettingGetGlobal_i(G, cSetting_ray_orthoscopic);
int last_grid_active = I->grid.active; int last_grid_active = I->grid.active;
int grid_size = 0; int grid_size = 0;
if(SettingGetGlobal_i(G, cSetting_defer_builds_mode) == 5) if(SettingGetGlobal_i(G, cSetting_defer_builds_mode) == 5)
SceneUpdate(G, true); SceneUpdate(G, true);
if(ortho < 0) if(ortho < 0)
ortho = SettingGetGlobal_b(G, cSetting_ortho); ortho = SettingGetGlobal_b(G, cSetting_ortho);
skipping to change at line 324 skipping to change at line 322
if(!quiet) { if(!quiet) {
PRINTFB(G, FB_Ray, FB_Blather) PRINTFB(G, FB_Ray, FB_Blather)
" Ray: tracing %dx%d = %d rays against %d primitives.\n", ray_width, " Ray: tracing %dx%d = %d rays against %d primitives.\n", ray_width,
ray_height, ray_width * ray_height, RayGetNPrimitives(ray) ray_height, ray_width * ray_height, RayGetNPrimitives(ray)
ENDFB(G); ENDFB(G);
} }
} }
switch (mode) { switch (mode) {
case 0: /* mode 0 is built-in */ case 0: /* mode 0 is built-in */
{ {
unsigned int buffer_size = 4 * ray_width * ray_height; auto image = pymol::make_unique<pymol::Image>(ray_width, ray_height);
unsigned int *buffer = (unsigned int*) Alloc(unsigned int, ray_width * std::uint32_t background;
ray_height);
unsigned int background;
ErrChkPtr(G, buffer);
RayRender(ray, buffer, timing, angle, antialias, &background); RayRender(ray, image->pixels(), timing, angle, antialias, &background) ;
/* RayRenderColorTable(ray,ray_width,ray_height,buffer); */ /* RayRenderColorTable(ray,ray_width,ray_height,buffer); */
if(!I->grid.active) { if(!I->grid.active) {
I->Image = Calloc(ImageType, 1); I->Image = std::move(image);
I->Image->data = (unsigned char *) buffer;
I->Image->size = buffer_size;
I->Image->width = ray_width;
I->Image->height = ray_height;
} else { } else {
if(!I->Image) { /* alloc on first pass */ if(!I->Image) { /* alloc on first pass */
I->Image = Calloc(ImageType, 1); I->Image = pymol::make_unique<pymol::Image>(tot_width, tot_height) ;
if(I->Image) { if(I->Image) {
unsigned int tot_size = 4 * tot_width * tot_height; unsigned int tot_size = tot_width * tot_height;
I->Image->data = Alloc(unsigned char, tot_size);
I->Image->size = tot_size;
I->Image->width = tot_width;
I->Image->height = tot_height;
{ /* fill with background color */ { /* fill with background color */
unsigned int i; unsigned int *ptr = I->Image->pixels();
unsigned int *ptr = (unsigned int *) I->Image->data; for(size_t i = 0; i < tot_size; ++i) {
for(i = 0; i < tot_size; i += 4) {
*(ptr++) = background; *(ptr++) = background;
} }
} }
} }
} }
/* merge in the latest rendering */ /* merge in the latest rendering */
if(I->Image && I->Image->data) { if(I->Image && I->Image->bits()) {
int i, j; int i, j;
unsigned int *src = buffer; unsigned int *src = image->pixels();
unsigned int *dst = (unsigned int *) I->Image->data; unsigned int *dst = I->Image->pixels();
dst += (ray_x + ray_y * tot_width); dst += (ray_x + ray_y * tot_width);
for(i = 0; i < ray_height; i++) { for(i = 0; i < ray_height; i++) {
for(j = 0; j < ray_width; j++) { for(j = 0; j < ray_width; j++) {
if(*src != background) if(*src != background)
*(dst) = *(src); *(dst) = *(src);
dst++; dst++;
src++; src++;
} }
dst += (tot_width - ray_width); dst += (tot_width - ray_width);
} }
} }
FreeP(buffer);
} }
I->DirtyFlag = false; I->DirtyFlag = false;
I->CopyType = true; I->CopyType = true;
I->CopyForced = true; I->CopyForced = true;
I->MovieOwnsImageFlag = false;
} }
break; break;
case 1: /* mode 1 is povray */ case 1: /* mode 1 is povray */
charVLA = VLACalloc(char, 100000); charVLA = VLACalloc(char, 100000);
headerVLA = VLACalloc(char, 2000); headerVLA = VLACalloc(char, 2000);
RayRenderPOV(ray, ray_width, ray_height, &headerVLA, &charVLA, RayRenderPOV(ray, ray_width, ray_height, &headerVLA, &charVLA,
I->FrontSafe, I->BackSafe, fov, angle, antialias); I->FrontSafe, I->BackSafe, fov, angle, antialias);
if(!(charVLA_ptr && headerVLA_ptr)) { /* immediate mode */ if(!(charVLA_ptr && headerVLA_ptr)) { /* immediate mode */
strcpy(prefix, SettingGet_s(G, NULL, NULL, cSetting_batch_prefix)); strcpy(prefix, SettingGet_s(G, NULL, NULL, cSetting_batch_prefix));
skipping to change at line 489 skipping to change at line 474
I->FrontSafe, I->BackSafe, fov); I->FrontSafe, I->BackSafe, fov);
} }
break; break;
} }
RayFree(ray); RayFree(ray);
} }
if(I->grid.active) if(I->grid.active)
GridSetRayViewport(&I->grid, -1, &ray_x, &ray_y, &ray_width, &ray_height); GridSetRayViewport(&I->grid, -1, &ray_x, &ray_y, &ray_width, &ray_height);
if((mode == 0) && I->Image && I->Image->data) { if((mode == 0) && I->Image && !I->Image->empty()) {
SceneApplyImageGamma(G, (unsigned int *) I->Image->data, I->Image->width, SceneApplyImageGamma(G, I->Image->pixels(), I->Image->getWidth(),
I->Image->height); I->Image->getHeight());
} }
stereo_hand--; stereo_hand--;
if((I->StereoMode == 0) || (stereo_hand <= 0)) if((I->StereoMode == 0) || (stereo_hand <= 0))
break; break;
else { else {
stereo_image = I->Image; stereo_image = I->Image;
I->Image = NULL;
} }
} }
if(stereo_image) { if(stereo_image) {
if(I->Image) { if(I->Image) {
switch (I->StereoMode) { switch (I->StereoMode) {
case cStereo_quadbuffer: case cStereo_quadbuffer:
case cStereo_geowall: case cStereo_geowall:
/* merge the two images into one pointer */ /* merge the two images into one */
I->Image->data = Realloc(I->Image->data, unsigned char, I->Image->size * I->Image->merge(*stereo_image);
2);
UtilCopyMem(I->Image->data + I->Image->size, stereo_image->data, I->Imag
e->size);
I->Image->stereo = true;
break; break;
case cStereo_crosseye: case cStereo_crosseye:
case cStereo_walleye: case cStereo_walleye:
{ {
/* merge the two images into one */ /* merge the two images into one */
auto merged_image =
pymol::Image(I->Image->getWidth() * 2, I->Image->getHeight());
unsigned char *merged_image = Alloc(unsigned char, I->Image->size * 2) unsigned int *q = merged_image.pixels();
;
unsigned int *q = (unsigned int *) merged_image;
unsigned int *l; unsigned int *l;
unsigned int *r; unsigned int *r;
int height, width; int height, width;
int a, b; int a, b;
if(I->StereoMode == 2) { if(I->StereoMode == 2) {
l = (unsigned int *) stereo_image->data; l = (unsigned int *) stereo_image->bits();
r = (unsigned int *) I->Image->data; r = (unsigned int *) I->Image->bits();
} else { } else {
r = (unsigned int *) stereo_image->data; r = (unsigned int *) stereo_image->bits();
l = (unsigned int *) I->Image->data; l = (unsigned int *) I->Image->bits();
} }
height = I->Image->height; height = I->Image->getHeight();
width = I->Image->width; width = I->Image->getWidth();
for(a = 0; a < height; a++) { for(a = 0; a < height; a++) {
for(b = 0; b < width; b++) for(b = 0; b < width; b++)
*(q++) = *(l++); *(q++) = *(l++);
for(b = 0; b < width; b++) for(b = 0; b < width; b++)
*(q++) = *(r++); *(q++) = *(r++);
} }
FreeP(I->Image->data); *I->Image = std::move(merged_image);
I->Image->data = merged_image;
I->Image->width *= 2;
I->Image->size *= 2;
} }
break; break;
case cStereo_anaglyph: case cStereo_anaglyph:
{ {
int big_endian; int big_endian;
{ {
unsigned int test; unsigned int test;
unsigned char *testPtr; unsigned char *testPtr;
test = 0xFF000000; test = 0xFF000000;
testPtr = (unsigned char *) &test; testPtr = (unsigned char *) &test;
big_endian = (*testPtr) & 0x01; big_endian = (*testPtr) & 0x01;
} }
{ {
extern float anaglyphR_constants[6][9]; extern float anaglyphR_constants[6][9];
extern float anaglyphL_constants[6][9]; extern float anaglyphL_constants[6][9];
unsigned int *l = (unsigned int *) stereo_image->data; unsigned int *l = stereo_image->pixels();
unsigned int *r = (unsigned int *) I->Image->data; unsigned int *r = I->Image->pixels();
int anaglyph_mode = SettingGetGlobal_i(G, cSetting_anaglyph_mode); int anaglyph_mode = SettingGetGlobal_i(G, cSetting_anaglyph_mode);
/* anaglyph scalars */ /* anaglyph scalars */
float * a_r = anaglyphR_constants[anaglyph_mode]; float * a_r = anaglyphR_constants[anaglyph_mode];
float * a_l = anaglyphL_constants[anaglyph_mode]; float * a_l = anaglyphL_constants[anaglyph_mode];
int height, width; int height, width;
int a, b; int a, b;
float _r[3] = {0.F,0.F,0.F}, _l[3] = {0.F,0.F,0.F}, _b[3] = {0.F,0.F, 0.F}; float _r[3] = {0.F,0.F,0.F}, _l[3] = {0.F,0.F,0.F}, _b[3] = {0.F,0.F, 0.F};
height = I->Image->height; height = I->Image->getHeight();
width = I->Image->width; width = I->Image->getWidth();
for(a = 0; a < height; a++) { for(a = 0; a < height; a++) {
for(b = 0; b < width; b++) { for(b = 0; b < width; b++) {
if(big_endian) { if(big_endian) {
/* original : RGBA /* original : RGBA
*r = (*l & 0x00FFFFFF) | (*r & 0xFF000000); *r = (*l & 0x00FFFFFF) | (*r & 0xFF000000);
*/ */
/* UNTESTED */ /* UNTESTED */
_l[0] = (float)((*r & 0xFF000000)); _l[0] = (float)((*r & 0xFF000000));
_l[1] = (float)((*r & 0x00FF0000) >> 16); _l[1] = (float)((*r & 0x00FF0000) >> 16);
skipping to change at line 651 skipping to change at line 631
} }
} }
} }
break; break;
case cStereo_stencil_by_row: case cStereo_stencil_by_row:
case cStereo_stencil_by_column: case cStereo_stencil_by_column:
case cStereo_stencil_checkerboard: case cStereo_stencil_checkerboard:
{ {
/* merge the two images into one */ /* merge the two images into one */
unsigned char *merged_image = Alloc(unsigned char, I->Image->size);
unsigned int *q = (unsigned int *) merged_image;
unsigned int *l;
unsigned int *r;
int height, width;
int a, b;
int parity = 0; int parity = 0;
if(I->StereoMode == cStereo_stencil_by_row) { if(I->StereoMode == cStereo_stencil_by_row) {
parity = I->StencilParity; parity = I->StencilParity;
if(I->Block->rect.bottom & 0x1) if(I->rect.bottom & 0x1)
parity = 1 - parity; parity = 1 - parity;
} }
l = (unsigned int *) stereo_image->data; unsigned int* l = stereo_image->pixels();
r = (unsigned int *) I->Image->data; unsigned int* r = I->Image->pixels();
height = I->Image->height; int height = I->Image->getHeight();
width = I->Image->width; int width = I->Image->getWidth();
for(a = 0; a < height; a++) { auto merged_image = pymol::Image(width, height);
for(b = 0; b < width; b++) { unsigned int *q = merged_image.pixels();
for (int a = 0; a < height; ++a) {
for (int b = 0; b < width; ++b) {
switch (I->StereoMode) { switch (I->StereoMode) {
case cStereo_stencil_by_row: case cStereo_stencil_by_row:
if((a + parity) & 0x1) { if((a + parity) & 0x1) {
*(q++) = *(l++); *(q++) = *(l++);
r++; r++;
} else { } else {
*(q++) = *(r++); *(q++) = *(r++);
l++; l++;
} }
break; break;
skipping to change at line 704 skipping to change at line 681
*(q++) = *(l++); *(q++) = *(l++);
r++; r++;
} else { } else {
*(q++) = *(r++); *(q++) = *(r++);
l++; l++;
} }
break; break;
} }
} }
} }
FreeP(I->Image->data); *I->Image = std::move(merged_image);
I->Image->data = merged_image;
} }
break; break;
} }
} }
FreeP(stereo_image->data);
FreeP(stereo_image);
} }
timing = UtilGetSeconds(G) - timing; timing = UtilGetSeconds(G) - timing;
if(mode != 2) { /* don't show timings for tests */ if(mode != 2) { /* don't show timings for tests */
accumTiming += timing; accumTiming += timing;
if(show_timing && !quiet) { if(show_timing && !quiet) {
if(!G->Interrupt) { if(!G->Interrupt) {
PRINTFB(G, FB_Ray, FB_Details) PRINTFB(G, FB_Ray, FB_Details)
" Ray: render time: %4.2f sec. = %3.1f frames/hour (%4.2f sec. accum.) .\n", " Ray: render time: %4.2f sec. = %3.1f frames/hour (%4.2f sec. accum.) .\n",
timing, 3600 / timing, accumTiming ENDFB(G); timing, 3600 / timing, accumTiming ENDFB(G);
skipping to change at line 746 skipping to change at line 720
} }
OrthoBusyFast(G, 20, 20); OrthoBusyFast(G, 20, 20);
PyMOL_SetBusy(G->PyMOL, false); PyMOL_SetBusy(G->PyMOL, false);
return true; return true;
#endif #endif
} }
static int SceneDeferredRay(DeferredRay * dr) static int SceneDeferredRay(DeferredRay * dr)
{ {
PyMOLGlobals *G = dr->G; PyMOLGlobals *G = dr->m_G;
SceneRay(G, dr->ray_width, dr->ray_height, dr->mode, SceneRay(G, dr->ray_width, dr->ray_height, dr->mode,
NULL, NULL, dr->angle, dr->shift, dr->quiet, NULL, NULL, dr->angle, dr->shift, dr->quiet,
NULL, dr->show_timing, dr->antialias); NULL, dr->show_timing, dr->antialias);
if((dr->mode == 0) && G->HaveGUI && SettingGetGlobal_b(G, cSetting_auto_copy_i mages)) { if((dr->mode == 0) && G->HaveGUI && SettingGetGlobal_b(G, cSetting_auto_copy_i mages)) {
#ifdef _PYMOL_IP_EXTRAS #ifdef _PYMOL_IP_EXTRAS
PParse(G, "cmd._copy_image(quiet=0)"); PParse(G, "cmd._copy_image(quiet=0)");
#else #else
#ifdef PYMOL_EVAL #ifdef PYMOL_EVAL
PRINTFB(G, FB_Scene, FB_Warnings) PRINTFB(G, FB_Scene, FB_Warnings)
" Warning: Clipboard image transfers disabled in Evaluation Builds.\n" END FB(G); " Warning: Clipboard image transfers disabled in Evaluation Builds.\n" END FB(G);
skipping to change at line 769 skipping to change at line 743
} }
return 1; return 1;
} }
int SceneDeferRay(PyMOLGlobals * G, int SceneDeferRay(PyMOLGlobals * G,
int ray_width, int ray_width,
int ray_height, int ray_height,
int mode, int mode,
float angle, float shift, int quiet, int show_timing, int anti alias) float angle, float shift, int quiet, int show_timing, int anti alias)
{ {
DeferredRay *dr = Calloc(DeferredRay, 1); auto dr = pymol::make_unique<DeferredRay>(G);
if(dr) { if(dr) {
DeferredInit(G, &dr->deferred);
dr->G = G;
dr->ray_width = ray_width; dr->ray_width = ray_width;
dr->ray_height = ray_height; dr->ray_height = ray_height;
dr->mode = mode; dr->mode = mode;
dr->angle = angle; dr->angle = angle;
dr->shift = shift; dr->shift = shift;
dr->quiet = quiet; dr->quiet = quiet;
dr->show_timing = show_timing; dr->show_timing = show_timing;
dr->antialias = antialias; dr->antialias = antialias;
dr->deferred.fn = (DeferredFn *) SceneDeferredRay; dr->fn = (DeferredFn *) SceneDeferredRay;
} }
OrthoDefer(G, &dr->deferred); OrthoDefer(G, std::move(dr));
return 1; return 1;
} }
void SceneRenderRayVolume(PyMOLGlobals * G, CScene *I){ void SceneRenderRayVolume(PyMOLGlobals * G, CScene *I){
#ifndef PURE_OPENGL_ES_2 #ifndef PURE_OPENGL_ES_2
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glPushMatrix(); glPushMatrix();
glLoadIdentity(); glLoadIdentity();
glOrtho(0, I->Width, 0, I->Height, -100, 100); glOrtho(0, I->Width, 0, I->Height, -100, 100);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glPushMatrix(); glPushMatrix();
glLoadIdentity(); glLoadIdentity();
#endif #endif
#ifndef PURE_OPENGL_ES_2 #ifndef PURE_OPENGL_ES_2
glRasterPos3f(0, 0, -1); glRasterPos3f(0, 0, -1);
#endif #endif
glDepthMask(GL_FALSE); glDepthMask(GL_FALSE);
#ifndef PURE_OPENGL_ES_2 #ifndef PURE_OPENGL_ES_2
if (PIsGlutThread() && I->Image && I->Image->data){ if (PIsGlutThread() && I->Image && !I->Image->empty()){
if (rayWidth == I->Width && rayHeight == I->Height){ if (rayWidth == I->Width && rayHeight == I->Height){
glDrawPixels(I->Image->width, I->Image->height, GL_RGBA, GL_UNSIGNED_BYTE, I->Image->data); glDrawPixels(I->Image->getWidth(), I->Image->getHeight(), GL_RGBA, GL_UNSI GNED_BYTE, I->Image->bits());
} else { } else {
SceneDrawImageOverlay(G, 1, NULL); SceneDrawImageOverlay(G, 1, NULL);
} }
} }
#endif #endif
glDepthMask(GL_TRUE); glDepthMask(GL_TRUE);
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
glDepthFunc(GL_ALWAYS); glDepthFunc(GL_ALWAYS);
#ifndef PURE_OPENGL_ES_2 #ifndef PURE_OPENGL_ES_2
if (PIsGlutThread() && rayWidth == I->Width && rayHeight == I->Height) if (PIsGlutThread() && rayWidth == I->Width && rayHeight == I->Height)
 End of changes. 37 change blocks. 
81 lines changed or deleted 49 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)