ObjectMesh refactor

This commit is contained in:
Jarrett Johnson
2019-11-13 12:39:23 -05:00
committed by Thomas Holder
parent aaffc6463e
commit 14e5cefb94
13 changed files with 274 additions and 392 deletions

View File

@@ -77,6 +77,11 @@ public:
}
};
template <typename T, typename... Args>
copyable_ptr<T> make_copyable(Args &&... args) {
return copyable_ptr<T>(new T(std::forward<Args>(args)...));
}
/**
* A unique pointer which copies to nullptr.
*/
@@ -104,4 +109,9 @@ public:
}
};
template <typename T, typename... Args>
cache_ptr<T> make_cache(Args &&... args) {
return cache_ptr<T>(new T(std::forward<Args>(args)...));
}
} // namespace pymol

View File

@@ -60,7 +60,7 @@ typedef struct PointType {
#define EdgePt(field,P2,P3,P4,P5) (*((PointType*)Fvoid4p(field,P2,P3,P4,P5)))
struct _CIsosurf {
struct CIsosurf {
PyMOLGlobals *G;
CField *VertexCodes;
CField *ActiveEdges;
@@ -73,9 +73,9 @@ struct _CIsosurf {
float Level;
int Code[256];
int *Num;
pymol::vla<int>* Num = nullptr;
int NSeg;
float *Line;
pymol::vla<float>* Line = nullptr;
};
@@ -116,9 +116,9 @@ PyObject *IsosurfAsPyList(PyMOLGlobals * G, Isofield * field)
PyList_SetItem(result, 0, PConvIntArrayToPyList(field->dimensions, 3));
PyList_SetItem(result, 1, PyInt_FromLong(field->save_points));
PyList_SetItem(result, 2, FieldAsPyList(G, field->data));
PyList_SetItem(result, 2, FieldAsPyList(G, field->data.get()));
if(field->save_points)
PyList_SetItem(result, 3, FieldAsPyList(G, field->points));
PyList_SetItem(result, 3, FieldAsPyList(G, field->points.get()));
else
PyList_SetItem(result, 3, PConvAutoNone(NULL));
return (PConvAutoNone(result));
@@ -153,72 +153,40 @@ Isofield *IsosurfNewFromPyList(PyMOLGlobals * G, PyObject * list)
/* TO ENABLE BACKWARDS COMPATIBILITY...
Always check ll when adding new PyList_GetItem's */
if(ok)
ok = ((result = pymol::malloc<Isofield>(1)) != nullptr);
if(ok) {
result->data = NULL;
result->points = NULL;
result->gradients = NULL;
}
ok = (result = new Isofield()) != nullptr;
if(ok)
ok = PConvPyListToIntArrayInPlace(PyList_GetItem(list, 0), result->dimensions, 3);
if(ok)
ok = PConvPyIntToInt(PyList_GetItem(list, 1), &result->save_points);
if(ok)
ok = ((result->data = FieldNewFromPyList(G, PyList_GetItem(list, 2))) != NULL);
if(ok){
result->data.reset(FieldNewFromPyList_From_List(G, list, 2));
ok = result->data != nullptr;
}
if(ok) {
if(result->save_points)
ok = ((result->points = FieldNewFromPyList(G, PyList_GetItem(list, 3))) != NULL);
if(result->save_points) {
result->points.reset(FieldNewFromPyList_From_List(G, list, 3));
ok = result->points != nullptr;
}
else {
for(a = 0; a < 3; a++)
dim4[a] = result->dimensions[a];
dim4[3] = 3;
ok = ((result->points = CField::make<float>(G, dim4, 4)) != NULL);
result->points.reset(CField::make<float>(G, dim4, 4));
ok = result->points != nullptr;
}
}
if(!ok) {
if(result) {
if(result->data)
DeleteP(result->data);
if(result->points)
DeleteP(result->points);
mfree(result);
result = NULL;
}
DeleteP(result);
}
return (result);
}
Isofield *IsosurfNewCopy(PyMOLGlobals * G, const Isofield * src)
{
int ok = true;
Isofield *result = pymol::calloc<Isofield>(1);
copy3f(src->dimensions, result->dimensions);
result->save_points = src->save_points;
result->data = new CField(*src->data);
result->points = new CField(*src->points);
result->gradients = NULL;
if(!ok) {
if(result->data)
DeleteP(result->data);
if(result->points)
DeleteP(result->points);
FreeP(result);
}
return result;
}
/*===========================================================================*/
void IsofieldComputeGradients(PyMOLGlobals * G, Isofield * field)
{
int dim[4];
int a, b, c;
CField *data = field->data;
CField *gradients;
CField *data = field->data.get();
if(!field->gradients) {
@@ -227,8 +195,8 @@ void IsofieldComputeGradients(PyMOLGlobals * G, Isofield * field)
for(a = 0; a < 3; a++)
dim[a] = field->dimensions[a];
dim[3] = 3;
field->gradients = CField::make<float>(G, dim, 4);
gradients = field->gradients;
field->gradients.reset(CField::make<float>(G, dim, 4));
auto gradients = field->gradients.get();
dim[3] = 3;
/* bulk internal */
@@ -373,43 +341,19 @@ void IsofieldComputeGradients(PyMOLGlobals * G, Isofield * field)
/*===========================================================================*/
Isofield *IsosurfFieldAlloc(PyMOLGlobals * G, int *dims)
Isofield::Isofield(PyMOLGlobals * G, const int * const dims)
{
int dim4[4];
int a;
Isofield *result;
for(a = 0; a < 3; a++)
dim4[a] = dims[a];
std::copy_n(dims, 3, dim4);
dim4[3] = 3;
/* Warning: ...FromPyList also allocs and inits from the heap */
result = pymol::malloc<Isofield>(1);
ErrChkPtr(G, result);
result->data = CField::make<float>(G, dims, 3);
ErrChkPtr(G, result->data);
result->points = CField::make<float>(G, dim4, 4);
ErrChkPtr(G, result->points);
result->dimensions[0] = dims[0];
result->dimensions[1] = dims[1];
result->dimensions[2] = dims[2];
result->save_points = true;
result->gradients = NULL;
return (result);
data.reset(CField::make<float>(G, dims, 3));
points.reset(CField::make<float>(G, dim4, 4));
std::copy_n(dims, 3, dimensions);
}
/*===========================================================================*/
void IsosurfFieldFree(PyMOLGlobals * G, Isofield * field)
{
DeleteP(field->gradients);
DeleteP(field->points);
DeleteP(field->data);
mfree(field);
}
/*===========================================================================*/
static void IsosurfCode(CIsosurf * II, const char *bits1, const char *bits2)
{
@@ -684,7 +628,7 @@ int IsosurfExpand(Isofield * field1, Isofield * field2, CCrystal * cryst,
y = 1.0F;
if(z > 1.0F)
z = 1.0F;
average += FieldInterpolatef(field1->data, a, b, c, x, y, z);
average += FieldInterpolatef(field1->data.get(), a, b, c, x, y, z);
cnt++;
} else {
/* allow 1 cell of extrapolation -- this saves us
@@ -697,7 +641,7 @@ int IsosurfExpand(Isofield * field1, Isofield * field2, CCrystal * cryst,
y = 1.0F;
if(z > 1.0F)
z = 1.0F;
extrapolate_average += FieldInterpolatef(field1->data, a, b, c, x, y, z);
extrapolate_average += FieldInterpolatef(field1->data.get(), a, b, c, x, y, z);
extrapolate_cnt++;
}
}
@@ -850,9 +794,9 @@ int IsosurfGetRange(PyMOLGlobals * G, Isofield * field,
/*===========================================================================*/
int IsosurfVolume(PyMOLGlobals * G, CSetting * set1, CSetting * set2,
Isofield * field, float level, int **num,
float **vert, int *range, int mode, int skip, float alt_level)
int IsosurfVolume(PyMOLGlobals* G, CSetting* set1, CSetting* set2,
Isofield* field, float level, pymol::vla<int>& num, pymol::vla<float>& vert,
int* range, int mode, int skip, float alt_level)
{
int ok = true;
CIsosurf *I;
@@ -867,8 +811,8 @@ int IsosurfVolume(PyMOLGlobals * G, CSetting * set1, CSetting * set2,
int c, i, j, k;
int x, y, z;
int range_store[6];
I->Num = *num;
I->Line = *vert;
I->Num = std::addressof(num);
I->Line = std::addressof(vert);
I->Skip = skip;
if(range) {
for(c = 0; c < 3; c++) {
@@ -887,16 +831,16 @@ int IsosurfVolume(PyMOLGlobals * G, CSetting * set1, CSetting * set2,
}
}
I->Coord = field->points;
I->Data = field->data;
I->Coord = field->points.get();
I->Data = field->data.get();
I->Level = level;
if(ok)
ok = IsosurfAlloc(G, I);
I->NLine = 0;
I->NSeg = 0;
VLACheck(I->Num, int, I->NSeg);
I->Num[I->NSeg] = I->NLine;
I->Num->check(I->NSeg);
(*I->Num)[I->NSeg] = I->NLine;
if(ok) {
switch (mode) {
@@ -970,13 +914,10 @@ int IsosurfVolume(PyMOLGlobals * G, CSetting * set1, CSetting * set2,
}
/* shrinks sizes for more efficient RAM usage */
VLASize(I->Line, float, I->NLine * 3);
VLASize(I->Num, int, I->NSeg + 1);
I->Line->resize(I->NLine * 3);
I->Num->resize(I->NSeg + 1);
(*I->Num)[I->NSeg] = 0; /* important - must terminate the segment list */
I->Num[I->NSeg] = 0; /* important - must terminate the segment list */
*vert = I->Line;
*num = I->Num;
if(!PIsGlutThread()) {
_IsosurfFree(I);
}
@@ -1066,9 +1007,9 @@ static int IsosurfGradients(PyMOLGlobals * G, CSetting * set1, CSetting * set2,
int n_seg = I->NSeg;
int n_line = I->NLine;
float *i_line = I->Line;
CField *i_data = I->Data;
int *i_num = I->Num;
auto& i_line = *I->Line;
auto i_data = I->Data;
auto& i_num = *I->Num;
/* get cascaded state, object, or global settings */
@@ -1105,8 +1046,8 @@ static int IsosurfGradients(PyMOLGlobals * G, CSetting * set1, CSetting * set2,
/* locals for performance */
CField *gradients = field->gradients;
CField *points = field->points;
CField *gradients = field->gradients.get();
CField *points = field->points.get();
/* flags marking excluded regions to avoid (currently wasteful) */
int *flag = NULL;
@@ -1504,8 +1445,6 @@ static int IsosurfGradients(PyMOLGlobals * G, CSetting * set1, CSetting * set2,
}
/* restore modified local copies */
I->Line = i_line;
I->Num = i_num;
I->NLine = n_line;
I->NSeg = n_seg;
return (ok);
@@ -1532,8 +1471,8 @@ static int IsosurfDrawPoints(CIsosurf * II)
O3Ptr(I->Data, i + 1, j, k, I->CurOff),
&(EdgePt(I->Point, i, j, k, 0).Point[0]));
VLACheck(I->Line, float, I->NLine * 3 + 2);
a = I->Line + (I->NLine * 3);
I->Line->check(I->NLine * 3 + 2);
a = I->Line->data() + (I->NLine * 3);
b = &(EdgePt(I->Point, i, j, k, 0).Point[0]);
*(a++) = *(b++);
*(a++) = *(b++);
@@ -1547,8 +1486,8 @@ static int IsosurfDrawPoints(CIsosurf * II)
O3Ptr(I->Data, i + 1, j, k, I->CurOff),
&(EdgePt(I->Point, i, j, k, 0).Point[0]));
VLACheck(I->Line, float, I->NLine * 3 + 2);
a = I->Line + (I->NLine * 3);
I->Line->check(I->NLine * 3 + 2);
a = I->Line->data() + (I->NLine * 3);
b = &(EdgePt(I->Point, i, j, k, 0).Point[0]);
*(a++) = *(b++);
*(a++) = *(b++);
@@ -1578,8 +1517,8 @@ static int IsosurfDrawPoints(CIsosurf * II)
O3Ptr(I->Data, i, j + 1, k, I->CurOff),
&(EdgePt(I->Point, i, j, k, 1).Point[0]));
VLACheck(I->Line, float, I->NLine * 3 + 2);
a = I->Line + (I->NLine * 3);
I->Line->check(I->NLine * 3 + 2);
a = I->Line->data() + (I->NLine * 3);
b = &(EdgePt(I->Point, i, j, k, 1).Point[0]);
*(a++) = *(b++);
*(a++) = *(b++);
@@ -1594,8 +1533,8 @@ static int IsosurfDrawPoints(CIsosurf * II)
O3Ptr(I->Data, i, j + 1, k, I->CurOff),
&(EdgePt(I->Point, i, j, k, 1).Point[0]));
VLACheck(I->Line, float, I->NLine * 3 + 2);
a = I->Line + (I->NLine * 3);
I->Line->check(I->NLine * 3 + 2);
a = I->Line->data() + (I->NLine * 3);
b = &(EdgePt(I->Point, i, j, k, 1).Point[0]);
*(a++) = *(b++);
*(a++) = *(b++);
@@ -1623,8 +1562,8 @@ static int IsosurfDrawPoints(CIsosurf * II)
O3Ptr(I->Data, i, j, k + 1, I->CurOff),
&(EdgePt(I->Point, i, j, k, 2).Point[0]));
VLACheck(I->Line, float, I->NLine * 3 + 2);
a = I->Line + (I->NLine * 3);
I->Line->check(I->NLine * 3 + 2);
a = I->Line->data() + (I->NLine * 3);
b = &(EdgePt(I->Point, i, j, k, 2).Point[0]);
*(a++) = *(b++);
*(a++) = *(b++);
@@ -1639,8 +1578,8 @@ static int IsosurfDrawPoints(CIsosurf * II)
O3Ptr(I->Data, i, j, k + 1, I->CurOff),
&(EdgePt(I->Point, i, j, k, 2).Point[0]));
VLACheck(I->Line, float, I->NLine * 3 + 2);
a = I->Line + (I->NLine * 3);
I->Line->check(I->NLine * 3 + 2);
a = I->Line->data() + (I->NLine * 3);
b = &(EdgePt(I->Point, i, j, k, 2).Point[0]);
*(a++) = *(b++);
*(a++) = *(b++);
@@ -1656,11 +1595,11 @@ static int IsosurfDrawPoints(CIsosurf * II)
}
}
if(ok) {
if(I->NLine != I->Num[I->NSeg]) { /* any new points? */
VLACheck(I->Num, int, I->NSeg + 1);
I->Num[I->NSeg] = I->NLine - I->Num[I->NSeg];
if(I->NLine != (*I->Num)[I->NSeg]) { /* any new points? */
I->Num->check(I->NSeg + 1);
(*I->Num)[I->NSeg] = I->NLine - (*I->Num)[I->NSeg];
I->NSeg++;
I->Num[I->NSeg] = I->NLine;
(*I->Num)[I->NSeg] = I->NLine;
}
}
return (ok);
@@ -1688,8 +1627,8 @@ static int IsosurfDrawLines(CIsosurf * II)
Start = EdgePtPtr(I->Point, i, j, k, c);
while(Start->NLink) {
Cur = Start;
VLACheck(I->Line, float, I->NLine * 3 + 2);
a = I->Line + (I->NLine * 3);
I->Line->check(I->NLine * 3 + 2);
a = I->Line->data() + (I->NLine * 3);
b = Cur->Point;
*(a++) = *(b++);
*(a++) = *(b++);
@@ -1734,8 +1673,8 @@ static int IsosurfDrawLines(CIsosurf * II)
#endif
Cur = Next;
VLACheck(I->Line, float, I->NLine * 3 + 2);
a = I->Line + (I->NLine * 3);
I->Line->check(I->NLine * 3 + 2);
a = I->Line->data() + (I->NLine * 3);
b = Cur->Point;
*(a++) = *(b++);
*(a++) = *(b++);
@@ -1746,12 +1685,12 @@ static int IsosurfDrawLines(CIsosurf * II)
LCount++;
#endif
Cur = NULL;
if(I->NLine != I->Num[I->NSeg]) { /* any new lines? */
VLACheck(I->Num, int, I->NSeg + 1);
I->Num[I->NSeg] = I->NLine - I->Num[I->NSeg];
if(I->NLine != (*I->Num)[I->NSeg]) { /* any new lines? */
I->Num->check(I->NSeg + 1);
(*I->Num)[I->NSeg] = I->NLine - (*I->Num)[I->NSeg];
I->NSeg++;
VLACheck(I->Num, int, I->NSeg);
I->Num[I->NSeg] = I->NLine;
I->Num->check(I->NSeg);
(*I->Num)[I->NSeg] = I->NLine;
}
}
}
@@ -2164,12 +2103,11 @@ static int IsosurfCodeVertices(CIsosurf * II)
* corner: output buffer of size 8 * 3
*/
void IsofieldGetCorners(PyMOLGlobals * G, Isofield * field, float * corner) {
CField * points = field->points;
int a, i, j, k;
for(a = 0; a < 8; a++) {
i = (a & 1) ? (points->dim[0] - 1) : 0;
j = (a & 2) ? (points->dim[1] - 1) : 0;
k = (a & 4) ? (points->dim[2] - 1) : 0;
CField* points = field->points.get();
for(int a = 0; a < 8; a++) {
int i = (a & 1) ? (points->dim[0] - 1) : 0;
int j = (a & 2) ? (points->dim[1] - 1) : 0;
int k = (a & 4) ? (points->dim[2] - 1) : 0;
memcpy(corner + a * 3, F3Ptr(points, i, j, k), 3 * sizeof(float));
}
}

View File

@@ -26,13 +26,15 @@ Z* -------------------------------------------------------------------
#include"PyMOLGlobals.h"
#include"Setting.h"
typedef struct {
int dimensions[3];
int save_points;
CField *points;
CField *data;
CField *gradients;
} Isofield;
struct Isofield {
int dimensions[3]{};
int save_points = true;
pymol::copyable_ptr<CField> points;
pymol::copyable_ptr<CField> data;
pymol::cache_ptr<CField> gradients;
Isofield() = default;
Isofield(PyMOLGlobals * G, const int * const dims);
};
#define F3(field,P1,P2,P3) Ffloat3(field,P1,P2,P3)
#define F3Ptr(field,P1,P2,P3) Ffloat3p(field,P1,P2,P3)
@@ -40,12 +42,9 @@ typedef struct {
#define F4(field,P1,P2,P3,P4) Ffloat4(field,P1,P2,P3,P4)
#define F4Ptr(field,P1,P2,P3,P4) Ffloat4p(field,P1,P2,P3,P4)
Isofield *IsosurfFieldAlloc(PyMOLGlobals * G, int *dims);
void IsosurfFieldFree(PyMOLGlobals * G, Isofield * field);
int IsosurfVolume(PyMOLGlobals * G, CSetting * set1, CSetting * set2,
Isofield * field, float level, int **num,
float **vert, int *range, int mode, int skip, float alt_level);
int IsosurfVolume(PyMOLGlobals* G, CSetting* set1, CSetting* set2,
Isofield* field, float level, pymol::vla<int>& num, pymol::vla<float>& vert,
int* range, int mode, int skip, float alt_level);
int IsosurfGetRange(PyMOLGlobals * G, Isofield * field, CCrystal * cryst,
float *mn, float *mx, int *range, int clamp);
@@ -61,7 +60,6 @@ void IsosurfFree(PyMOLGlobals * G);
void IsofieldComputeGradients(PyMOLGlobals * G, Isofield * field);
PyObject *IsosurfAsPyList(PyMOLGlobals *G, Isofield * I);
Isofield *IsosurfNewFromPyList(PyMOLGlobals * G, PyObject * list);
Isofield *IsosurfNewCopy(PyMOLGlobals * G, const Isofield * src);
void IsofieldGetCorners(PyMOLGlobals *, Isofield *, float *);

View File

@@ -39,7 +39,7 @@ typedef int lexidx_t;
typedef int lexborrow_t;
typedef struct _CMemoryCache CMemoryCache;
typedef struct _CIsosurf CIsosurf;
struct CIsosurf;
typedef struct _CTetsurf CTetsurf;
typedef struct _CSphere CSphere;
struct CFeedback;

View File

@@ -563,9 +563,9 @@ int TetsurfVolume(PyMOLGlobals * G, Isofield * field, float level, int **num,
}
*/
I->Coord = field->points;
I->Grad = field->gradients;
I->Data = field->data;
I->Coord = field->points.get();
I->Grad = field->gradients.get();
I->Data = field->data.get();
I->Level = level;
if(ok)
ok = TetsurfAlloc(I);

View File

@@ -250,8 +250,8 @@ int ObjectMapStateGetExcludedStats(PyMOLGlobals * G, ObjectMapState * ms, float
int ObjectMapStateGetDataRange(PyMOLGlobals * G, ObjectMapState * ms, float *min,
float *max)
{
float max_val = 0.0F, min_val = 0.0F;
CField *data = ms->Field->data;
float max_val = 0.0F, min_val = 0.0F;
CField *data = ms->Field->data.get();
int cnt = data->dim[0] * data->dim[1] * data->dim[2];
float *raw_data = (float *) data->data.data();
if(cnt) {
@@ -294,7 +294,7 @@ int ObjectMapStateGetHistogram(PyMOLGlobals * G, ObjectMapState * ms,
float sum = 0.0f, sumsq = 0.0f;
float min_his, max_his, irange, mean, stdev;
int pos;
CField *data = ms->Field->data;
CField *data = ms->Field->data.get();
int cnt = data->dim[0] * data->dim[1] * data->dim[2];
float *raw_data = (float *) data->data.data();
if(cnt) {
@@ -475,7 +475,7 @@ static int ObjectMapStateTrim(PyMOLGlobals * G, ObjectMapState * ms,
orig_size = fdim[0] * fdim[1] * fdim[2];
new_size = new_fdim[0] * new_fdim[1] * new_fdim[2];
field = IsosurfFieldAlloc(G, new_fdim);
field = new Isofield(G, new_fdim);
field->save_points = ms->Field->save_points;
for(c = 0; c < new_fdim[2]; c++) {
@@ -491,7 +491,7 @@ static int ObjectMapStateTrim(PyMOLGlobals * G, ObjectMapState * ms,
}
}
}
IsosurfFieldFree(G, ms->Field);
DeleteP(ms->Field);
for(a = 0; a < 3; a++) {
ms->Min[a] = new_min[a];
ms->Max[a] = new_max[a];
@@ -579,7 +579,7 @@ static int ObjectMapStateTrim(PyMOLGlobals * G, ObjectMapState * ms,
orig_size = fdim[0] * fdim[1] * fdim[2];
new_size = new_fdim[0] * new_fdim[1] * new_fdim[2];
field = IsosurfFieldAlloc(G, new_fdim);
field = new Isofield(G, new_fdim);
field->save_points = ms->Field->save_points;
for(c = 0; c < new_fdim[2]; c++) {
@@ -595,7 +595,7 @@ static int ObjectMapStateTrim(PyMOLGlobals * G, ObjectMapState * ms,
}
}
}
IsosurfFieldFree(G, ms->Field);
DeleteP(ms->Field);
for(a = 0; a < 3; a++) {
ms->Min[a] = new_min[a];
ms->Max[a] = new_max[a];
@@ -658,7 +658,7 @@ static int ObjectMapStateDouble(PyMOLGlobals * G, ObjectMapState * ms)
fdim[a] = ms->FDim[a] * 2 - 1;
}
fdim[3] = 3;
field = IsosurfFieldAlloc(G, fdim);
field = new Isofield(G, fdim);
field->save_points = ms->Field->save_points;
for(c = 0; c < fdim[2]; c++) {
v[2] = (c + min[2]) / ((float) div[2]);
@@ -673,7 +673,7 @@ static int ObjectMapStateDouble(PyMOLGlobals * G, ObjectMapState * ms)
vt = F4Ptr(field->points, a, b, c, 0);
copy3f(vr, vt);
if((a & 0x1) || (b & 0x1) || (c & 0x1)) {
F3(field->data, a, b, c) = FieldInterpolatef(ms->Field->data,
F3(field->data, a, b, c) = FieldInterpolatef(ms->Field->data.get(),
a / 2, b / 2, c / 2, x, y, z);
} else {
F3(field->data, a, b, c) = F3(ms->Field->data, a / 2, b / 2, c / 2);
@@ -681,7 +681,7 @@ static int ObjectMapStateDouble(PyMOLGlobals * G, ObjectMapState * ms)
}
}
}
IsosurfFieldFree(G, ms->Field);
DeleteP(ms->Field);
for(a = 0; a < 3; a++) {
ms->Min[a] = min[a];
ms->Max[a] = max[a];
@@ -699,7 +699,7 @@ static int ObjectMapStateDouble(PyMOLGlobals * G, ObjectMapState * ms)
}
fdim[3] = 3;
field = IsosurfFieldAlloc(G, fdim);
field = new Isofield(G, fdim);
field->save_points = ms->Field->save_points;
for(c = 0; c < fdim[2]; c++) {
@@ -714,7 +714,7 @@ static int ObjectMapStateDouble(PyMOLGlobals * G, ObjectMapState * ms)
vt = F4Ptr(field->points, a, b, c, 0);
copy3f(v, vt);
if((a & 0x1) || (b & 0x1) || (c & 0x1)) {
F3(field->data, a, b, c) = FieldInterpolatef(ms->Field->data,
F3(field->data, a, b, c) = FieldInterpolatef(ms->Field->data.get(),
a / 2, b / 2, c / 2, x, y, z);
} else {
F3(field->data, a, b, c) = F3(ms->Field->data, a / 2, b / 2, c / 2);
@@ -722,7 +722,7 @@ static int ObjectMapStateDouble(PyMOLGlobals * G, ObjectMapState * ms)
}
}
}
IsosurfFieldFree(G, ms->Field);
DeleteP(ms->Field);
for(a = 0; a < 3; a++) {
ms->Min[a] = min[a];
ms->Max[a] = max[a];
@@ -776,9 +776,9 @@ static int ObjectMapStateHalve(PyMOLGlobals * G, ObjectMapState * ms, int smooth
old_max = ms->Max;
if(smooth)
FieldSmooth3f(ms->Field->data);
FieldSmooth3f(ms->Field->data.get());
field = IsosurfFieldAlloc(G, fdim);
field = new Isofield(G, fdim);
field->save_points = ms->Field->save_points;
/*
@@ -815,12 +815,12 @@ static int ObjectMapStateHalve(PyMOLGlobals * G, ObjectMapState * ms, int smooth
transform33f3f(ms->Symmetry->Crystal.FracToReal, v, vr);
vt = F4Ptr(field->points, a, b, c, 0);
copy3f(vr, vt);
F3(field->data, a, b, c) = FieldInterpolatef(ms->Field->data,
F3(field->data, a, b, c) = FieldInterpolatef(ms->Field->data.get(),
a_2, b_2, c_2, x, y, z);
}
}
}
IsosurfFieldFree(G, ms->Field);
DeleteP(ms->Field);
for(a = 0; a < 3; a++) {
ms->Min[a] = min[a];
ms->Max[a] = max[a];
@@ -870,7 +870,7 @@ static int ObjectMapStateHalve(PyMOLGlobals * G, ObjectMapState * ms, int smooth
}
fdim[3] = 3;
field = IsosurfFieldAlloc(G, fdim);
field = new Isofield(G, fdim);
field->save_points = ms->Field->save_points;
for(c = 0; c < fdim[2]; c++) {
@@ -885,7 +885,7 @@ static int ObjectMapStateHalve(PyMOLGlobals * G, ObjectMapState * ms, int smooth
}
}
}
IsosurfFieldFree(G, ms->Field);
DeleteP(ms->Field);
for(a = 0; a < 3; a++) {
ms->Min[a] = min[a];
ms->Max[a] = max[a];
@@ -1112,7 +1112,7 @@ int ObjectMapStateInterpolate(ObjectMapState * ms, const float *array, float *re
c = ms->FDim[2] + ms->Min[2] - 1;
}
/* printf("%d %d %d %8.3f %8.3f %8.3f\n",a,b,c,x,y,z); */
*(result++) = FieldInterpolatef(ms->Field->data,
*(result++) = FieldInterpolatef(ms->Field->data.get(),
a - ms->Min[0],
b - ms->Min[1], c - ms->Min[2], x, y, z);
if(flag)
@@ -1179,7 +1179,7 @@ int ObjectMapStateInterpolate(ObjectMapState * ms, const float *array, float *re
*flag = 0;
}
/* printf("%d %d %d %8.3f %8.3f %8.3f\n",a,b,c,x,y,z); */
*(result++) = FieldInterpolatef(ms->Field->data,
*(result++) = FieldInterpolatef(ms->Field->data.get(),
a - ms->Min[0],
b - ms->Min[1], c - ms->Min[2], x, y, z);
if(flag)
@@ -1366,7 +1366,7 @@ static int ObjectMapStateCopy(PyMOLGlobals * G, const ObjectMapState * src, Obje
copy3f(src->Max, I->Max);
copy3f(src->FDim, I->FDim);
I->Field = IsosurfNewCopy(G, src->Field);
I->Field = new Isofield(*src->Field);
I->State = src->State;
if(ok)
ObjectMapStateRegeneratePoints(I);
@@ -1698,10 +1698,7 @@ int ObjectMapStateSetBorder(ObjectMapState * I, float level)
void ObjectMapStatePurge(PyMOLGlobals * G, ObjectMapState * I)
{
ObjectStatePurge(&I->State);
if(I->Field) {
IsosurfFieldFree(G, I->Field);
I->Field = NULL;
}
DeleteP(I->Field);
FreeP(I->Origin);
FreeP(I->Dim);
FreeP(I->Range);
@@ -1939,7 +1936,7 @@ void ObjectMap::render(RenderInfo * info)
if((I->visRep & cRepDotBit)) {
if(!ms->have_range) {
double sum = 0.0, sumsq = 0.0;
CField *data = ms->Field->data;
CField *data = ms->Field->data.get();
int cnt = data->dim[0] * data->dim[1] * data->dim[2];
float *raw_data = (float *) data->data.data();
int a;
@@ -1962,13 +1959,13 @@ void ObjectMap::render(RenderInfo * info)
}
if(ms->have_range) {
int a;
CField *data = ms->Field->data;
CField *data = ms->Field->data.get();
int cnt = data->dim[0] * data->dim[1] * data->dim[2];
CField *points = ms->Field->points;
CField *points = ms->Field->points.get();
CField *gradients = NULL;
if(SettingGet_b(G, NULL, I->Setting, cSetting_dot_normals)) {
gradients = ms->Field->gradients;
gradients = ms->Field->gradients.get();
}
if(data && points) {
float *raw_data = (float *) data->data.data();
@@ -2200,7 +2197,7 @@ ObjectMapState *ObjectMapNewStateFromDesc(PyMOLGlobals * G, ObjectMap * I,
ms->FDim[a] = ms->Max[a] - ms->Min[a] + 1;
ms->FDim[3] = 3;
ms->Field = IsosurfFieldAlloc(I->G, ms->FDim);
ms->Field = new Isofield(I->G, ms->FDim);
if(!ms->Field)
ok = false;
else {
@@ -2635,7 +2632,7 @@ static int ObjectMapCCP4StrToMap(ObjectMap * I, char *CCP4Str, int bytes, int st
else {
SymmetryUpdate(ms->Symmetry);
/* CrystalDump(ms->Crystal); */
ms->Field = IsosurfFieldAlloc(I->G, ms->FDim);
ms->Field = new Isofield(I->G, ms->FDim);
ms->MapSource = cMapSourceCCP4;
ms->Field->save_points = false;
@@ -3044,7 +3041,7 @@ static int ObjectMapPHIStrToMap(ObjectMap * I, char *PHIStr, int bytes, int stat
ms->Max[1] = ms->Div[1];
ms->Max[2] = ms->Div[2];
ms->Field = IsosurfFieldAlloc(I->G, ms->FDim);
ms->Field = new Isofield(I->G, ms->FDim);
ms->MapSource = cMapSourceGeneralPurpose;
ms->Field->save_points = false;
@@ -3330,7 +3327,7 @@ static int ObjectMapXPLORStrToMap(ObjectMap * I, char *XPLORStr, int state, int
ok = false;
else {
SymmetryUpdate(ms->Symmetry);
ms->Field = IsosurfFieldAlloc(I->G, ms->FDim);
ms->Field = new Isofield(I->G, ms->FDim);
ms->MapSource = cMapSourceCrystallographic;
ms->Field->save_points = false;
for(c = 0; c < ms->FDim[2]; c++) {
@@ -3618,7 +3615,7 @@ static int ObjectMapFLDStrToMap(ObjectMap * I, char *PHIStr, int bytes, int stat
ms->Grid[a] = 0.0F;
}
ms->Field = IsosurfFieldAlloc(I->G, ms->FDim);
ms->Field = new Isofield(I->G, ms->FDim);
ms->MapSource = cMapSourceFLD;
ms->Field->save_points = false;
@@ -4014,7 +4011,7 @@ static int ObjectMapBRIXStrToMap(ObjectMap * I, char *BRIXStr, int bytes, int st
ok = false;
else {
SymmetryUpdate(ms->Symmetry);
ms->Field = IsosurfFieldAlloc(I->G, ms->FDim);
ms->Field = new Isofield(I->G, ms->FDim);
ms->MapSource = cMapSourceBRIX;
ms->Field->save_points = false;
@@ -4500,7 +4497,7 @@ end d
}
SymmetryUpdate(ms->Symmetry);
ms->Field = IsosurfFieldAlloc(I->G, ms->FDim);
ms->Field = new Isofield(I->G, ms->FDim);
ms->MapSource = cMapSourceGRD;
ms->Field->save_points = false;
@@ -5049,7 +5046,7 @@ static int ObjectMapDXStrToMap(ObjectMap * I, char *DXStr, int bytes, int state,
" DXStrToMap: %d data points.\n", n_items ENDFB(I->G);
}
ms->Field = IsosurfFieldAlloc(I->G, ms->FDim);
ms->Field = new Isofield(I->G, ms->FDim);
ms->MapSource = cMapSourceGeneralPurpose;
ms->Field->save_points = false;
@@ -5289,7 +5286,7 @@ static int ObjectMapACNTStrToMap(ObjectMap * I, char *ACNTStr, int bytes, int st
" ACNTStrToMap: %d data points.\n", n_items ENDFB(I->G);
}
ms->Field = IsosurfFieldAlloc(I->G, ms->FDim);
ms->Field = new Isofield(I->G, ms->FDim);
ms->MapSource = cMapSourceGeneralPurpose;
ms->Field->save_points = false;
@@ -5634,7 +5631,7 @@ static int ObjectMapNumPyArrayToMapState(PyMOLGlobals * G, ObjectMapState * ms,
if(!(ms->FDim[0] && ms->FDim[1] && ms->FDim[2]))
ok = false;
else {
ms->Field = IsosurfFieldAlloc(G, ms->FDim);
ms->Field = new Isofield(G, ms->FDim);
for(c = 0; c < ms->FDim[2]; c++) {
v[2] = ms->Origin[2] + ms->Grid[2] * c;
for(b = 0; b < ms->FDim[1]; b++) {
@@ -5879,7 +5876,7 @@ ObjectMap *ObjectMapLoadChemPyMap(PyMOLGlobals * G, ObjectMap * I, PyObject * Ma
ok = false;
else {
SymmetryUpdate(ms->Symmetry);
ms->Field = IsosurfFieldAlloc(G, ms->FDim);
ms->Field = new Isofield(G, ms->FDim);
for(c = 0; c < ms->FDim[2]; c++) {
v[2] = (c + ms->Min[2]) / ((float) ms->Div[2]);
for(b = 0; b < ms->FDim[1]; b++) {

View File

@@ -37,10 +37,8 @@ Z* -------------------------------------------------------------------
#include"P.h"
#include"Matrix.h"
#include"ShaderMgr.h"
#include"CGO.h"
#include"ObjectCGO.h"
static void ObjectMeshStateInit(PyMOLGlobals * G, ObjectMeshState * ms);
static void ObjectMeshRecomputeExtent(ObjectMesh * I);
static PyObject *ObjectMeshStateAsPyList(ObjectMeshState * I)
@@ -70,7 +68,7 @@ static PyObject *ObjectMeshStateAsPyList(ObjectMeshState * I)
PyList_SetItem(result, 14, PyFloat_FromDouble(I->AltLevel));
PyList_SetItem(result, 15, PyInt_FromLong(I->quiet));
if(I->Field) {
PyList_SetItem(result, 16, IsosurfAsPyList(I->State.G, I->Field));
PyList_SetItem(result, 16, IsosurfAsPyList(I->G, I->Field.get()));
} else {
PyList_SetItem(result, 16, PConvAutoNone(NULL));
}
@@ -122,7 +120,7 @@ static int ObjectMeshStateFromPyList(PyMOLGlobals * G, ObjectMeshState * I,
if(!PyList_Check(list))
I->Active = false;
else {
ObjectMeshStateInit(G, I);
*I = ObjectMeshState(G);
if(ok)
ok = (list != NULL);
if(ok)
@@ -183,8 +181,11 @@ static int ObjectMeshStateFromPyList(PyMOLGlobals * G, ObjectMeshState * I,
tmp = PyList_GetItem(list, 16);
if(tmp == Py_None)
I->Field = NULL;
else
ok = ((I->Field = IsosurfNewFromPyList(G, tmp)) != NULL);
else {
I->Field.reset(IsosurfNewFromPyList(G, tmp));
ok = I->Field != nullptr;
}
CPythonVal_Free(tmp);
}
}
}
@@ -277,39 +278,6 @@ PyObject *ObjectMeshAsPyList(ObjectMesh * I)
return (PConvAutoNone(result));
}
static void ObjectMeshStatePurge(ObjectMeshState * ms)
{
ObjectStatePurge(&ms->State);
if(ms->Field) {
IsosurfFieldFree(ms->State.G, ms->Field);
ms->Field = NULL;
}
VLAFreeP(ms->AtomVertex);
CGOFree(ms->shaderCGO);
CGOFree(ms->shaderUnitCellCGO);
CGOFree(ms->UnitCellCGO);
ms->Active = false;
}
static void ObjectMeshStateFree(ObjectMeshState * ms)
{
ObjectMeshStatePurge(ms);
VLAFreeP(ms->N);
VLAFreeP(ms->V);
FreeP(ms->VC);
FreeP(ms->RC);
}
ObjectMesh::~ObjectMesh()
{
auto I = this;
for(int a = 0; a < I->NState; a++) {
if(I->State[a].Active)
ObjectMeshStateFree(I->State + a);
}
VLAFreeP(I->State);
}
int ObjectMeshInvalidateMapName(ObjectMesh * I, const char *name, const char * new_name)
{
int a;
@@ -341,8 +309,8 @@ void ObjectMeshDump(ObjectMesh * I, const char *fname, int state, int quiet)
}
else {
if(state < I->NState) {
n = I->State[state].N;
v = I->State[state].V;
n = I->State[state].N.data();
v = I->State[state].V.data();
if(n && v)
while(*n) {
c = *(n++);
@@ -374,8 +342,8 @@ void ObjectMesh::invalidate(int rep, int level, int state)
for(StateIterator iter(I->G, NULL, state, I->NState); iter.next();) {
ObjectMeshState *ms = I->State + iter.state;
CGOFree(ms->shaderCGO);
CGOFree(ms->shaderUnitCellCGO);
ms->shaderCGO.reset();
ms->shaderUnitCellCGO.reset();
ms->RefreshFlag = true;
if(level >= cRepInvAll) {
@@ -449,7 +417,7 @@ static void ObjectMeshStateUpdateColors(ObjectMesh * I, ObjectMeshState * ms)
ms->OneColor = cur_color;
if(ms->V) {
int ramped_flag = false;
float *v = ms->V;
float *v = ms->V.data();
float *vc;
int *rc;
int a;
@@ -457,20 +425,20 @@ static void ObjectMeshStateUpdateColors(ObjectMesh * I, ObjectMeshState * ms)
int n_vert = VLAGetSize(ms->V) / 3;
int base_n_vert = ms->base_n_V / 3;
if(ms->VC && (ms->VCsize < n_vert)) {
FreeP(ms->VC);
FreeP(ms->RC);
if(!ms->VC.empty() && (ms->VCsize < n_vert)) {
ms->VC.clear();
ms->RC.clear();
}
if(!ms->VC) {
if(ms->VC.empty()) {
ms->VCsize = n_vert;
ms->VC = pymol::malloc<float>(n_vert * 3);
ms->VC = std::vector<float>(n_vert * 3);
}
if(!ms->RC) {
ms->RC = pymol::malloc<int>(n_vert);
if(ms->RC.empty()) {
ms->RC = std::vector<int>(n_vert);
}
rc = ms->RC;
vc = ms->VC;
rc = ms->RC.data();
vc = ms->VC.data();
if(vc) {
for(a = 0; a < n_vert; a++) {
if(a == base_n_vert) {
@@ -498,12 +466,12 @@ static void ObjectMeshStateUpdateColors(ObjectMesh * I, ObjectMeshState * ms)
}
if(one_color_flag && (!ramped_flag)) {
FreeP(ms->VC);
FreeP(ms->RC);
ms->VC.clear();
ms->RC.clear();
} else if((!ramped_flag)
||
(!SettingGet_b(I->G, NULL, I->Setting, cSetting_ray_color_ramps))) {
FreeP(ms->RC);
ms->RC.clear();
}
}
}
@@ -521,8 +489,6 @@ void ObjectMesh::update()
float *v;
float carve_buffer;
int avoid_flag = false;
int *old_n;
float *old_v;
int n_cur;
int n_seg;
int n_line;
@@ -554,14 +520,13 @@ void ObjectMesh::update()
}
if((I->visRep & cRepCellBit)) {
CGOFree(ms->UnitCellCGO);
ms->UnitCellCGO = CrystalGetUnitCellCGO(&ms->Crystal);
ms->UnitCellCGO.reset(CrystalGetUnitCellCGO(&ms->Crystal));
}
if(!oms->State.Matrix.empty()) {
ObjectStateSetMatrix(&ms->State, oms->State.Matrix.data());
} else if(!ms->State.Matrix.empty()) {
ObjectStateResetMatrix(&ms->State);
ObjectStateSetMatrix(ms, oms->State.Matrix.data());
} else if(!ms->Matrix.empty()) {
ObjectStateResetMatrix(ms);
}
ms->RefreshFlag = false;
}
@@ -577,7 +542,7 @@ void ObjectMesh::update()
" ObjectMesh: updating \"%s\".\n", I->Name ENDFB(G);
}
if(ms->Field) {
field = ms->Field;
field = ms->Field.get();
} else if(oms->Field) {
field = oms->Field;
}
@@ -586,7 +551,7 @@ void ObjectMesh::update()
{
float *min_ext, *max_ext;
float tmp_min[3], tmp_max[3];
if(MatrixInvTransformExtentsR44d3f(ms->State.Matrix.data(),
if(MatrixInvTransformExtentsR44d3f(ms->Matrix.data(),
ms->ExtentMin, ms->ExtentMax,
tmp_min, tmp_max)) {
min_ext = tmp_min;
@@ -609,7 +574,7 @@ void ObjectMesh::update()
IsosurfVolume(I->G, I->Setting, NULL,
field,
ms->Level,
&ms->N, &ms->V,
ms->N, ms->V,
ms->Range, ms->MeshMode, mesh_skip, ms->AltLevel);
if(!SettingGet_b
@@ -618,13 +583,13 @@ void ObjectMesh::update()
} else if(ms->MeshMode != 3) {
/* do we want the negative surface too? */
int *N2 = VLAlloc(int, 10000);
float *V2 = VLAlloc(float, 10000);
pymol::vla<int> N2(10000);
pymol::vla<float> V2(10000);
IsosurfVolume(I->G, I->Setting, NULL,
field,
-ms->Level,
&N2, &V2, ms->Range, ms->MeshMode, mesh_skip, ms->AltLevel);
N2, V2, ms->Range, ms->MeshMode, mesh_skip, ms->AltLevel);
if(N2 && V2) {
@@ -642,12 +607,12 @@ void ObjectMesh::update()
/* copy vertex data */
memcpy(((char *) ms->V) + (sizeof(float) * base_n_V),
memcpy(((char *) ms->V.data()) + (sizeof(float) * base_n_V),
V2, sizeof(float) * addl_n_V);
/* copy strip counts */
memcpy(((char *) ms->N) + (sizeof(int) * (base_n_N - 1)),
memcpy(((char *) ms->N.data()) + (sizeof(int) * (base_n_N - 1)),
N2, sizeof(int) * addl_n_N);
ms->N[base_n_N + addl_n_N - 1] = 0;
@@ -657,13 +622,13 @@ void ObjectMesh::update()
}
if(!ms->State.Matrix.empty() && VLAGetSize(ms->N) && VLAGetSize(ms->V)) {
if(!ms->Matrix.empty() && VLAGetSize(ms->N) && VLAGetSize(ms->V)) {
int count;
/* take map coordinates back to view coordinates if necessary */
v = ms->V;
v = ms->V.data();
count = VLAGetSize(ms->V) / 3;
while(count--) {
transform44d3f(ms->State.Matrix.data(), v, v);
transform44d3f(ms->Matrix.data(), v, v);
v += 3;
}
}
@@ -684,13 +649,13 @@ void ObjectMesh::update()
MapSetupExpress(voxelmap);
old_n = ms->N;
old_v = ms->V;
ms->N = VLAlloc(int, VLAGetSize(old_n));
ms->V = VLAlloc(float, VLAGetSize(old_v));
pymol::vla<int> old_n = std::move(ms->N);
pymol::vla<float> old_v = std::move(ms->V);
ms->N = pymol::vla<int>(old_n.size());
ms->V = pymol::vla<float>(old_v.size());
n = old_n;
v = old_v;
n = old_n.data();
v = old_v.data();
n_cur = 0;
n_seg = 0;
n_line = 0;
@@ -743,8 +708,6 @@ void ObjectMesh::update()
}
VLACheck(ms->N, int, n_seg);
ms->N[n_seg] = 0;
VLAFreeP(old_n);
VLAFreeP(old_v);
MapFree(voxelmap);
}
}
@@ -755,8 +718,8 @@ void ObjectMesh::update()
}
}
CGOFree(ms->shaderCGO);
CGOFree(ms->shaderUnitCellCGO);
ms->shaderCGO.reset();
ms->shaderUnitCellCGO.reset();
}
SceneInvalidate(I->G);
}
@@ -786,7 +749,7 @@ static short ObjectMeshStateRenderShader(ObjectMeshState *ms, ObjectMesh *I,
SceneGetTwoSidedLighting(G));
}
CGORenderGL(ms->shaderCGO, NULL, NULL, NULL, info, NULL);
CGORenderGL(ms->shaderCGO.get(), NULL, NULL, NULL, info, NULL);
if (shaderPrg) {
shaderPrg->Disable();
@@ -795,7 +758,7 @@ static short ObjectMeshStateRenderShader(ObjectMeshState *ms, ObjectMesh *I,
if (ms->shaderUnitCellCGO){
shaderPrg = G->ShaderMgr->Enable_DefaultShader(info->pass);
shaderPrg->SetLightingEnabled(0);
CGORenderGL(ms->shaderUnitCellCGO, NULL, NULL, NULL, info, NULL);
CGORenderGL(ms->shaderUnitCellCGO.get(), NULL, NULL, NULL, info, NULL);
shaderPrg->Disable();
}
@@ -838,14 +801,14 @@ static CGO *ObjectMeshRenderImpl(ObjectMesh * I, RenderInfo * info, int returnCG
continue;
{
v = ms->V;
n = ms->N;
v = ms->V.data();
n = ms->N.data();
if(ok && ray) {
if(ms->UnitCellCGO && (I->visRep & cRepCellBit)){
ok &= CGORenderRay(ms->UnitCellCGO, ray, info, ColorGet(I->G, I->Color),
ok &= CGORenderRay(ms->UnitCellCGO.get(), ray, info, ColorGet(I->G, I->Color),
NULL, I->Setting, NULL);
if (!ok){
CGOFree(ms->UnitCellCGO);
ms->UnitCellCGO.reset();
break;
}
}
@@ -868,8 +831,8 @@ static CGO *ObjectMeshRenderImpl(ObjectMesh * I, RenderInfo * info, int returnCG
float cc[3];
float colA[3], colB[3];
ColorGetEncoded(G, ms->OneColor, cc);
vc = ms->VC;
rc = ms->RC;
vc = ms->VC.data();
rc = ms->RC.data();
if(ms->MeshMode == 1) {
ray->color3fv(cc);
while(ok && *n) {
@@ -931,8 +894,8 @@ static CGO *ObjectMeshRenderImpl(ObjectMesh * I, RenderInfo * info, int returnCG
mesh_as_cylinders = SettingGetGlobal_b(G, cSetting_render_as_cylinders) && SettingGetGlobal_b(G, cSetting_mesh_as_cylinders) && ms->MeshMode != 1;
if (ms->shaderCGO && (!use_shader || (mesh_as_cylinders ^ ms->shaderCGO->has_draw_cylinder_buffers))){
CGOFree(ms->shaderCGO);
CGOFree(ms->shaderUnitCellCGO);
ms->shaderCGO.reset();
ms->shaderUnitCellCGO.reset();
}
if (ms->shaderCGO && !returnCGO) {
@@ -952,12 +915,12 @@ static CGO *ObjectMeshRenderImpl(ObjectMesh * I, RenderInfo * info, int returnCG
if(ms->UnitCellCGO && (I->visRep & cRepCellBit)) {
const float *color = ColorGet(I->G, I->Color);
if (!use_shader) {
CGORenderGL(ms->UnitCellCGO, color, I->Setting, NULL, info, NULL);
CGORenderGL(ms->UnitCellCGO.get(), color, I->Setting, NULL, info, NULL);
} else if(!ms->shaderUnitCellCGO) {
CGO *newUnitCellCGO = CGONewSized(G, 0);
CGOColorv(newUnitCellCGO, color);
CGOAppend(newUnitCellCGO, ms->UnitCellCGO);
ms->shaderUnitCellCGO = CGOOptimizeToVBONotIndexedNoShader(newUnitCellCGO, 0);
CGOAppend(newUnitCellCGO, ms->UnitCellCGO.get());
ms->shaderUnitCellCGO.reset(CGOOptimizeToVBONotIndexedNoShader(newUnitCellCGO, 0));
CGOFree(newUnitCellCGO);
ms->shaderUnitCellCGO->use_shader = true;
}
@@ -979,7 +942,7 @@ static CGO *ObjectMeshRenderImpl(ObjectMesh * I, RenderInfo * info, int returnCG
}
if(n && v && (I->visRep & cRepMeshBit)) {
if(use_shader) {
vc = ms->VC;
vc = ms->VC.data();
if(!vc)
ok &= CGOColorv(shaderCGO, ColorGet(I->G, ms->OneColor));
@@ -1048,7 +1011,8 @@ static CGO *ObjectMeshRenderImpl(ObjectMesh * I, RenderInfo * info, int returnCG
}
}
} else {
vc = ms->VC;
#ifndef PURE_OPENGL_ES_2
vc = ms->VC.data();
if(!vc)
glColor3fv(ColorGet(I->G, ms->OneColor));
@@ -1074,6 +1038,7 @@ static CGO *ObjectMeshRenderImpl(ObjectMesh * I, RenderInfo * info, int returnCG
}
glEnd();
}
#endif
}
}
if(info && !info->line_lighting){
@@ -1097,14 +1062,14 @@ static CGO *ObjectMeshRenderImpl(ObjectMesh * I, RenderInfo * info, int returnCG
if (returnCGO){
return (shaderCGO);
} else {
ms->shaderCGO = shaderCGO;
ms->shaderCGO.reset(shaderCGO);
}
if (ok){
if (mesh_as_cylinders){
CGO *tmpCGO = CGONew(G);
ok &= CGOEnable(tmpCGO, GL_CYLINDER_SHADER);
if (ok) ok &= CGOSpecial(tmpCGO, MESH_WIDTH_FOR_SURFACES);
convertcgo = CGOConvertShaderCylindersToCylinderShader(ms->shaderCGO, tmpCGO);
convertcgo = CGOConvertShaderCylindersToCylinderShader(ms->shaderCGO.get(), tmpCGO);
if (ok) ok &= CGOAppendNoStop(tmpCGO, convertcgo);
if (ok) ok &= CGODisable(tmpCGO, GL_CYLINDER_SHADER);
if (ok) ok &= CGOStop(tmpCGO);
@@ -1112,13 +1077,12 @@ static CGO *ObjectMeshRenderImpl(ObjectMesh * I, RenderInfo * info, int returnCG
convertcgo = tmpCGO;
convertcgo->use_shader = convertcgo->has_draw_cylinder_buffers = true;
} else {
convertcgo = CGOOptimizeToVBONotIndexedWithReturnedData(ms->shaderCGO, 0, false, NULL);
convertcgo = CGOOptimizeToVBONotIndexedWithReturnedData(ms->shaderCGO.get(), 0, false, NULL);
}
CHECKOK(ok, convertcgo);
}
if (convertcgo){
CGOFree(ms->shaderCGO);
ms->shaderCGO = convertcgo;
ms->shaderCGO.reset(convertcgo);
}
}
@@ -1152,37 +1116,18 @@ int ObjectMesh::getNFrame() const
ObjectMesh::ObjectMesh(PyMOLGlobals * G) : CObject(G)
{
auto I = this;
I->State = VLACalloc(ObjectMeshState, 10); /* autozero important */
I->State = pymol::vla<ObjectMeshState>(10); /* autozero important */
I->type = cObjectMesh;
}
/*========================================================================*/
void ObjectMeshStateInit(PyMOLGlobals * G, ObjectMeshState * ms)
ObjectMeshState::ObjectMeshState(PyMOLGlobals* G)
: CObjectState(G)
, Crystal(G)
{
if(ms->Active)
ObjectMeshStatePurge(ms);
ObjectStateInit(G, &ms->State);
if(!ms->V) {
ms->V = VLAlloc(float, 10000);
}
if(!ms->N) {
ms->N = VLAlloc(int, 10000);
}
ms->N[0] = 0;
ms->Active = true;
ms->ResurfaceFlag = true;
ms->RecolorFlag = false;
ms->ExtentFlag = false;
ms->CarveFlag = false;
ms->quiet = true;
ms->CarveBuffer = 0.0;
ms->AtomVertex = NULL;
ms->UnitCellCGO = NULL;
ms->caption[0] = 0;
ms->Field = NULL;
ms->shaderCGO = NULL;
ms->shaderUnitCellCGO = NULL;
V = pymol::vla<float>(10000);
N = pymol::vla<int>(10000);
}
@@ -1221,7 +1166,7 @@ ObjectMesh *ObjectMeshFromXtalSym(PyMOLGlobals * G, ObjectMesh * obj, ObjectMap
if (ok){
ms = I->State + state;
ObjectMeshStateInit(G, ms);
*ms = ObjectMeshState(G);
}
if (ok){
@@ -1247,15 +1192,15 @@ ObjectMesh *ObjectMeshFromXtalSym(PyMOLGlobals * G, ObjectMesh * obj, ObjectMap
copy3f(mx, ms->ExtentMax);
if(!oms->State.Matrix.empty()) {
ok &= ObjectStateSetMatrix(&ms->State, oms->State.Matrix.data());
} else if(!ms->State.Matrix.empty()) {
ObjectStateResetMatrix(&ms->State);
ok &= ObjectStateSetMatrix(ms, oms->State.Matrix.data());
} else if(!ms->Matrix.empty()) {
ObjectStateResetMatrix(ms);
}
if (ok) {
float *min_ext, *max_ext;
float tmp_min[3], tmp_max[3];
if(MatrixInvTransformExtentsR44d3f(ms->State.Matrix.data(),
if(MatrixInvTransformExtentsR44d3f(ms->Matrix.data(),
ms->ExtentMin, ms->ExtentMax,
tmp_min, tmp_max)) {
min_ext = tmp_min;
@@ -1278,10 +1223,10 @@ ObjectMesh *ObjectMeshFromXtalSym(PyMOLGlobals * G, ObjectMesh * obj, ObjectMap
fdim[0] = eff_range[3] - eff_range[0];
fdim[1] = eff_range[4] - eff_range[1];
fdim[2] = eff_range[5] - eff_range[2];
ms->Field = IsosurfFieldAlloc(I->G, fdim);
ms->Field = pymol::make_copyable<Isofield>(I->G, fdim);
expand_result =
IsosurfExpand(oms->Field, ms->Field, &oms->Symmetry->Crystal, sym, eff_range);
IsosurfExpand(oms->Field, ms->Field.get(), &oms->Symmetry->Crystal, sym, eff_range);
if(expand_result == 0) {
ok = false;
@@ -1321,7 +1266,7 @@ ObjectMesh *ObjectMeshFromXtalSym(PyMOLGlobals * G, ObjectMesh * obj, ObjectMap
if(carve != 0.0) {
ms->CarveFlag = true;
ms->CarveBuffer = carve;
ms->AtomVertex = vert_vla;
ms->AtomVertex = pymol::vla_take_ownership(vert_vla);
}
if(I) {
ObjectMeshRecomputeExtent(I);

View File

@@ -18,44 +18,47 @@ Z* -------------------------------------------------------------------
#define _H_ObjectMesh
#include"ObjectMap.h"
#include "CGO.h"
#include"Word.h"
#include"Symmetry.h"
typedef struct {
CObjectState State;
ObjectNameType MapName;
struct ObjectMeshState : public CObjectState {
ObjectNameType MapName{};
int MapState;
CCrystal Crystal;
int Active;
int *N, *RC, VCsize, base_n_V;
int Active = true;
pymol::vla<int> N;
std::vector<int> RC;
int VCsize, base_n_V;
int OneColor;
float *V, *VC;
int Range[6];
float ExtentMin[3], ExtentMax[3];
int ExtentFlag;
pymol::vla<float> V;
std::vector<float> VC;
int Range[6]{};
float ExtentMin[3]{}, ExtentMax[3]{};
int ExtentFlag = false;
float Level, Radius;
int RefreshFlag;
int ResurfaceFlag;
int quiet;
int RecolorFlag;
float *AtomVertex;
int CarveFlag;
float CarveBuffer;
int ResurfaceFlag = true;
int quiet = true;
int RecolorFlag = false;
pymol::vla<float> AtomVertex;
int CarveFlag = false;
float CarveBuffer = 0.0f;
int MeshMode;
CGO *UnitCellCGO;
WordType caption;
pymol::cache_ptr<CGO, CGODeleter> UnitCellCGO;
WordType caption{};
float AltLevel;
pymol::copyable_ptr<Isofield> Field;
/* not stored */
Isofield *Field;
CGO *shaderCGO;
CGO *shaderUnitCellCGO;
} ObjectMeshState;
pymol::cache_ptr<CGO, CGODeleter> shaderCGO;
pymol::cache_ptr<CGO, CGODeleter> shaderUnitCellCGO;
ObjectMeshState(PyMOLGlobals* G);
};
struct ObjectMesh : public CObject {
ObjectMeshState *State;
pymol::vla<ObjectMeshState> State;
int NState = 0;
ObjectMesh(PyMOLGlobals* G);
~ObjectMesh();
// virtual methods
void update() override;

View File

@@ -306,10 +306,7 @@ static void ObjectVolumeStateFree(ObjectVolumeState * vs)
if(vs->State.G->HaveGUI) {
vs->State.G->ShaderMgr->freeGPUBuffers(vs->textures, 3);
}
if(vs->Field) {
IsosurfFieldFree(vs->State.G, vs->Field);
vs->Field = NULL;
}
DeleteP(vs->Field);
DeleteP(vs->carvemask);
VLAFreeP(vs->AtomVertex);
if (vs->Ramp)
@@ -386,8 +383,8 @@ static CField * ObjectVolumeStateGetField(ObjectVolumeState * vs) {
if (!vs)
return NULL;
if(vs->Field)
return vs->Field->data;
return ObjectVolumeStateGetMapState(vs)->Field->data;
return vs->Field->data.get();
return ObjectVolumeStateGetMapState(vs)->Field->data.get();
}
CField * ObjectVolumeGetField(ObjectVolume * I) {
@@ -1133,10 +1130,7 @@ void ObjectVolumeStateInit(PyMOLGlobals * G, ObjectVolumeState * vs)
{
if(vs->Active)
ObjectStatePurge(&vs->State);
if(vs->Field) {
IsosurfFieldFree(vs->State.G, vs->Field);
vs->Field = NULL;
}
DeleteP(vs->Field);
vs->State = CObjectState(G);
if(vs->AtomVertex) {
VLAFreeP(vs->AtomVertex);
@@ -1233,7 +1227,7 @@ ObjectVolume *ObjectVolumeFromXtalSym(PyMOLGlobals * G, ObjectVolume * obj, Obje
fdim[0] = eff_range[3] - eff_range[0];
fdim[1] = eff_range[4] - eff_range[1];
fdim[2] = eff_range[5] - eff_range[2];
vs->Field = IsosurfFieldAlloc(I->G, fdim);
vs->Field = new Isofield(I->G, fdim);
expand_result =
IsosurfExpand(oms->Field, vs->Field, &oms->Symmetry->Crystal, sym, eff_range);

View File

@@ -37,9 +37,10 @@ Z* -------------------------------------------------------------------
typedef struct RepMesh {
Rep R;
int *N;
pymol::vla<int> N;
int NTot;
float *V, *VC;
pymol::vla<float> V;
float* VC;
int NDot;
float *Dot;
float Radius, Width;
@@ -62,8 +63,6 @@ void RepMeshFree(RepMesh * I)
I->shaderCGO = 0;
}
FreeP(I->VC);
VLAFreeP(I->V);
VLAFreeP(I->N);
FreeP(I->LastColor);
FreeP(I->LastVisib);
OOFreeP(I);
@@ -76,9 +75,9 @@ int RepMeshGetSolventDots(RepMesh * I, CoordSet * cs, float *min, float *max,
static int RepMeshCGOGenerate(RepMesh * I, RenderInfo * info)
{
PyMOLGlobals *G = I->R.G;
float *v = I->V;
float *v = I->V.data();
float *vc = I->VC;
int *n = I->N;
int *n = I->N.data();
int ok = true;
short use_shader;
short mesh_as_cylinders;
@@ -302,9 +301,9 @@ static void RepMeshRender(RepMesh * I, RenderInfo * info)
CRay *ray = info->ray;
auto pick = info->pick;
PyMOLGlobals *G = I->R.G;
float *v = I->V;
float *v = I->V.data();
float *vc = I->VC;
int *n = I->N;
int *n = I->N.data();
int c;
const float *col = NULL;
float line_width = SceneGetDynamicLineWidth(info, I->Width);
@@ -626,7 +625,7 @@ void RepMeshColor(RepMesh * I, CoordSet * cs)
c1 = 1;
minDist = FLT_MAX;
i0 = -1;
v0 = I->V + 3 * a;
v0 = I->V.data() + 3 * a;
MapLocus(map, v0, &h, &k, &l);
i = *(MapEStart(map, h, k, l));
@@ -892,10 +891,10 @@ Rep *RepMeshNew(CoordSet * cs, int state)
}
if (ok)
I->V = (float*) VLAMalloc(1000, sizeof(float), 9, false);
I->V = pymol::vla_take_ownership((float*)VLAMalloc(1000, sizeof(float), 9, false));
CHECKOK(ok, I->V);
if (ok)
I->N = (int*) VLAMalloc(100, sizeof(int), 9, false);
I->N = pymol::vla_take_ownership((int*)VLAMalloc(100, sizeof(int), 9, false));
CHECKOK(ok, I->N);
if (ok)
I->N[0] = 0;
@@ -946,7 +945,7 @@ Rep *RepMeshNew(CoordSet * cs, int state)
for(c = 0; c < 3; c++)
dims[c] = (int) ((sizeE[c] / gridSize) + 1.5F);
field = IsosurfFieldAlloc(G, dims);
field = new Isofield(G, dims);
CHECKOK(ok, field);
}
@@ -1057,19 +1056,18 @@ Rep *RepMeshNew(CoordSet * cs, int state)
FreeP(I->Dot);
OrthoBusyFast(G, 2, 3);
if(ok) {
ok &= IsosurfVolume(G, NULL, NULL, field, 1.0, &I->N, &I->V, NULL, mesh_type, mesh_skip,
ok &= IsosurfVolume(G, NULL, NULL, field, 1.0, I->N, I->V, NULL, mesh_type, mesh_skip,
1.0F);
}
if (field)
IsosurfFieldFree(G, field);
if(ok && (I->N && I->V && (carve_flag || clear_flag || trim_flag))) {
DeleteP(field);
if(ok && (I->N.data() && I->V.data() && (carve_flag || clear_flag || trim_flag))) {
int cur_size = VLAGetSize(I->N);
if((mesh_type == 0) && cur_size) {
int *n = I->N;
int *n = I->N.data();
int *new_n = VLACalloc(int, cur_size);
int new_size = 0;
float *new_v = I->V;
float *v = I->V;
float *new_v = I->V.data();
float *v = I->V.data();
CHECKOK(ok, new_n);
while(ok && (c = *(n++))) {
int new_c = 0;
@@ -1165,8 +1163,7 @@ Rep *RepMeshNew(CoordSet * cs, int state)
new_c = 0;
}
}
VLAFreeP(I->N);
I->N = new_n;
I->N = pymol::vla_take_ownership(new_n);
}
}
MapFree(trim_map);
@@ -1175,7 +1172,7 @@ Rep *RepMeshNew(CoordSet * cs, int state)
VLAFreeP(trim_vla);
VLAFreeP(carve_vla);
VLAFreeP(clear_vla);
n = I->N;
n = I->N.data();
I->NTot = 0;
if (ok){
while(*n)

View File

@@ -4489,7 +4489,7 @@ CField * ExecutiveGetVolumeField(PyMOLGlobals * G, const char * objName, int sta
case cObjectMap:
oms = ObjectMapGetState((ObjectMap *) obj, state);
ok_assert(1, oms && oms->Field);
return oms->Field->data;
return oms->Field->data.get();
}
ok_except1:

View File

@@ -489,7 +489,7 @@ ObjectMap *PlugIOManagerLoadVol(PyMOLGlobals * G, ObjectMap * obj,
}
// field
ms->Field = IsosurfFieldAlloc(G, ms->FDim);
ms->Field = new Isofield(G, ms->FDim);
ms->MapSource = cMapSourceVMDPlugin;
ms->Field->save_points = false; /* save points in RAM only, not session file */
ms->Active = true;

View File

@@ -6023,8 +6023,8 @@ int SelectorMapCoulomb(PyMOLGlobals * G, int sele1, ObjectMapState * oMap,
if(n_point) {
int *min = oMap->Min;
int *max = oMap->Max;
CField *data = oMap->Field->data;
CField *points = oMap->Field->points;
CField *data = oMap->Field->data.get();
CField *points = oMap->Field->points.get();
float dist;
if(cutoff > 0.0F) { /* we are using a cutoff */