Ejemplo n.º 1
0
CVisComplexObj::~CVisComplexObj()
{
	logToFile((f, "VisComplexObj is to be deleted\n"));
	int i;
	for (i = 0; i < aiTopIndex; ++i) 
	{
        logToFile((f, "arrays[%d]: 0x%p\n", i, arrays[i]));
		FreeDoubleArray(arrays[i]);
    }
    logToFile((f, "scrVertices: 0x%p\n", scrVertices));
	FreeDoubleArray(scrVertices);
	Show=0;
	update(ACTION_DELETE, (double *)NULL, 0);
    logToFile((f, "VisComplexObj has been deleted\n"));
}
Ejemplo n.º 2
0
static int FitterReturn(FitParameters *fp, LevMar *lm, int retval)
{
    if (fp) {
        if (fp->pp) free(fp->pp);
        if (fp->pold) FreeDoubleVector(fp->pold);
        if (fp->pq) free(fp->pq);
        if (fp->d) FreeDoubleVector(fp->d);
        fp->pp = fp->pq = NULL;
        fp->d = fp->pold = NULL;
    }
    if (lm) {
        if (lm->C)   FreeDoubleArray(lm->C, fp->nFit, fp->nFit);
        if (lm->H)   FreeDoubleArray(lm->H, fp->nFit, fp->nFit);
        if (lm->rhs) FreeDoubleVector(lm->rhs);
        if (lm->dp)  FreeDoubleVector(lm->dp);
    }
    
    return retval;
}
Ejemplo n.º 3
0
STDMETHODIMP CVisComplexObj::get_polygonStipple(VARIANT *pVal)
{
    double *data = getPolygonStipple();
    double *newdata = CopyDoubleArrayStruct(data);
	if (newdata)
		for (int i=0; i<32; ++i)
			newdata[i] = ((unsigned int *)data)[i];
    VariantFromDoubleArray(newdata, pVal);
    FreeDoubleArray(newdata);
	return S_OK;
}
Ejemplo n.º 4
0
static int ret_mem(int *size)
{    
    if (!size) return 1;

    if (A)     FreeDoubleArray(A,     *size, *size);
    if (H)     FreeDoubleArray(H,     *size + 2, *size + 2);
#ifdef LAPACK
    if (H1)    FreeDoubleVector(H1);
    if (IPIV)  FreeIntVector(IPIV);
#endif
    if (B)     FreeDoubleVector(B);
    if (C)     FreeDoubleVector(C);
    if (P)     FreeDoubleVector(P);
    if (rhs)   FreeDoubleVector(rhs);
    if (f)     FreeDoubleVector(f);
    if (f_old) FreeDoubleVector(f_old);
    if (x_f)   FreeDoubleVector(x_f);
    if (y_f)   FreeDoubleVector(y_f);
    
    A =     NULL;
    H =     NULL;
#ifdef LAPACK
    H1 =    NULL;
    IPIV =  NULL;
#endif
    B =     NULL;
    C =     NULL;
    P =     NULL;
    rhs =   NULL;
    f =     NULL;
    f_old = NULL;
    x_f =   NULL;
    y_f =   NULL;
    
    *size = 0;
    
    return 0;
}
Ejemplo n.º 5
0
STDMETHODIMP CVisComplexObj::get_indices(VARIANT *pVal)
{
    double *data = getIndices();
    double *newdata = CopyDoubleArrayStruct(data);
	if (newdata)
	{
		int len = GetLength(data);
		for (int i=0; i<len; ++i)
			newdata[i] = ((unsigned int *)data)[i];
    }
	VariantFromDoubleArray(newdata, pVal);
    FreeDoubleArray(newdata);
	return S_OK;
}
Ejemplo n.º 6
0
STDMETHODIMP CVisComplexObj::put_vertices(VARIANT newVal)
{
	double *data;
	HRESULT result = VariantToDoubleArray(&data, &newVal);
	logToFile((f, "putVertices: %d\n", result));
	if (result) return E_INVALIDARG;
    if (data != NULL)
    {
        if (GetDim(data) != 2) return E_INVALIDARG;
        if (GetLength(data, 0) != 2 && GetLength(data, 0) != 3) return E_INVALIDARG;
    }
	setVertices(data);
    FreeDoubleArray(scrVertices);
    scrVertices = CopyDoubleArrayStruct(getVertices());
    updateScrVertices();
	return S_OK;
}
Ejemplo n.º 7
0
STDMETHODIMP CVComplexShape::SetVertices(VARIANT newVal, long iLogID)
{
	double *data;
	HRESULT result = VariantToDoubleArray(&data, &newVal);
	if (result) return E_INVALIDARG;
    if (data != NULL)
    {
        if (GetDim(data) < 2) return E_INVALIDARG;
        if (GetLength(data, 0) != 2 && GetLength(data, 0) != 3) return E_INVALIDARG;
    }
	setArray(aiVertices,data);
    FreeDoubleArray(scrVertices);
    scrVertices = CopyDoubleArrayStruct(m_getVertices());
    updateScrVertices();

    m_RequestUpdate(iLogID);
	return S_OK;
}
Ejemplo n.º 8
0
CVComplexShape::~CVComplexShape()
{
	int i;
	for (i=0; i<aiTopIndex; ++i) FreeDoubleArray(arrays[i]);
	FreeDoubleArray(scrVertices);
}
Ejemplo n.º 9
0
static void DoInterpolateMap(Widget w, StdForm *sf, XmListCallbackStruct *cb)
{
    int i, j, nX, nY;
    int err, type, order, corners;
    double xspa, yspa;
    string buf;
    MAP *m, *old = (MAP *)sf->any;
    int **L;
    double **A;
    
    int FillHolesInArray(), InterpolateArray();
    void FreeIntArray(), FreeDoubleArray();
    int **AllocIntArray();
    double **AllocDoubleArray();
    void send_line(), wsscanf(), SetWatchCursor();
    void MapDraw(), SetIntpOrder();
    int GetIntpType(), GetIntpOrder(), GetIntpCorners();
    MAP *new_map();
    list *get_maplist();

    if (!old) {
        PostErrorDialog(w, "No map selected to be interpolated.");
        return;
    }
    
    type    = GetIntpType();
    order   = GetIntpOrder();
    corners = GetIntpCorners();
    
    if (order <= 0) {
        PostWarningDialog(w, "Selected interpolation order is zero.");
        return;
    }
    
    nX   = old->i_no;
    nY   = old->j_no;
    xspa = old->xspacing;
    yspa = old->yspacing;
    
    A = AllocDoubleArray(nX, nY);
    if (!A) {
        PostErrorDialog(NULL, "InterpolateMap: Out of memory.");
        return;
    }
    L = AllocIntArray(nX, nY);
    if (!L) {
        FreeDoubleArray(A, nX, nY);
        PostErrorDialog(NULL, "InterpolateMap: Out of memory.");
        return;
    }
    
    SetWatchCursor(True);
    
    for (i=0; i<nX; i++) {
        for (j=0; j<nY; j++) {
            A[i][j] = old->d[i][j];
            if (old->f[i][j] <= BLANK)
                L[i][j] = EMPTY;
            else
                L[i][j] = FILLED;
        }
    }

    if (corners > 0)
        err = FillHolesInArray(A, L, nX, nY, corners);

    if ((i = order)) {
        while (i) {
            err = InterpolateArray(&A, &L, &nX, &nY, type);
            if (err != 0) {
                sprintf(buf, "Couldn't interpolate array. err=%d.", err);
                send_line(buf);
                if (A) FreeDoubleArray(A, nX, nY);
                if (L) FreeIntArray(L, nX, nY);
                SetWatchCursor(False);
                PostErrorDialog(NULL, buf);
                return;
            }
            xspa /= 2.0;
            yspa /= 2.0;
            i--;
            if (corners > 0)
                err = FillHolesInArray(A, L, nX, nY, corners);
        }
    }

    m = new_map(get_maplist(), nX, nY);
    
    m->type     = old->type;
    m->swapped  = old->swapped;
    m->memed    = old->memed;
    m->original = old->original;
    m->x0       = old->x0;
    m->y0       = old->y0;
    m->xleft    = old->xleft;
    m->xright   = old->xright;
    m->ylower   = old->ylower;
    m->yupper   = old->yupper;
    m->date     = old->date;
    strcpy(m->molecule, old->molecule);
    m->interpolated = old->interpolated + 1;
    m->equinox  = old->equinox;
    m->epoch    = old->epoch;
    
    m->ndata    = nX * nY;
    m->i_min    = NINT(m->xleft/xspa);
    m->i_max    = NINT(m->xright/xspa);
    m->j_min    = NINT(m->ylower/yspa);
    m->j_max    = NINT(m->yupper/yspa);
    m->xspacing = xspa;
    m->yspacing = yspa;
    
    for (i=0; i<nX; i++) {
        for (j=0; j<nY; j++) {
            if (L[i][j] == FILLED) {
                m->f[i][j] = UNBLANK;
                m->d[i][j] = A[i][j];
                m->e[i][j] = UNDEF;
            } else {
                m->f[i][j] = BLANK;
                m->d[i][j] = UNDEF;
                m->e[i][j] = UNDEF;
            }
        }
    }
    
    FreeDoubleArray(A, nX, nY);
    FreeIntArray(L, nX, nY);

    SetWatchCursor(False);

    wsscanf(sf->edit[0], m->name);
    sprintf(buf, "Interpolated map stored as '%s': %dx%d\n",  m->name, nX, nY);
    send_line(buf);
    
    XtDestroyWidget(sf->form);
    
    SetIntpOrder(0);
    MapDraw(NULL, m, NULL);
}