Exemplo n.º 1
0
	void PCPolyhedron::addToModel(const PCPtr& nuCloud)
	{
		PCModelObject::addToModel(nuCloud);

		/// 1 - Detectar caras de la nueva nube
		/// 2 - Descartar caras que no pertenecen a la caja (caras de la mano)
		/// 3 - Matchear caras de la nube anterior con las nuevas caras
		/// 4 - Estimar caras ocultas (?)
		
		PCPtr trimmedCloud = getHalo(this->getvMin(),this->getvMax(),0.05,nuCloud);
		
		saveCloud("nucloud.pcd",*nuCloud);
		saveCloud("trimmed.pcd",*trimmedCloud);

		pcPolygonsMutex.lock();
		vector<PCPolygonPtr> prevPcPolygons = pcpolygons;

		//Detecto nuevas caras
		vector<PCPolygonPtr> nuevos = detectPolygons(trimmedCloud,Constants::OBJECT_PLANE_TOLERANCE(),Constants::CLOUD_VOXEL_SIZE * 2,false); 
		
		//Matching de las caras detectadas con las anteriores
		nuevos = mergePolygons(nuevos);

		//Estimación de caras no visibles
		bool estimationOK;
		vector<PCPolygonPtr> estimated = estimateHiddenPolygons(nuevos,estimationOK);

		bool valid = true;
		if(estimationOK)
		{
			for(int i = 0; i < nuevos.size(); i++)
				nuevos.at(i)->setEstimated(false);
			//Actualizo los nuevos polygons si no hubo errores
			nuevos.insert(nuevos.end(),estimated.begin(),estimated.end());
			pcpolygons = nuevos;

			//Unifico vertices
			unifyVertexs();

			isvalid = validate();
		}

		//Chequeo volumenes
		if(IsFeatureActive(FEATURE_INVALIDATE_OBJECT_BY_VOLUME))
		{
			float inVol = computeVolume(trimmedCloud);

			if(getVolume() < inVol * Constants::OBJECT_VOLUME_TOLERANCE)
			{
				cout << "[   INVALID VOLUME    ]" << endl;
				cout << "need: " << inVol * 0.6 << "  --- has: " << getVolume() << endl;
				isvalid = false;
			}
		}
		
		if(estimationOK && isvalid)
		{
			polygonsCache.clear();
			for (vector<PCPolygonPtr>::iterator p = pcpolygons.begin(); p != pcpolygons.end(); ++p)
			{
				polygonsCache.push_back((*p)->getPolygonModelObject());
			}

		}
		else
		{
			pcpolygons = prevPcPolygons;

			//Si hay errores en la estimación, rollback de los pcpolygons mergeados
			for(int i = 0; i < pcpolygons.size(); i++)
				pcpolygons.at(i)->rollBackMatching();

			if(!isvalid)
			{
				//Necesito unificar los vertices despues del rollback
				unifyVertexs();
			}
			isvalid = false;
		}
		
		//Seteo nueva nube
		PCPtr finalCloud (new PC());
		for(int i = 0; i < pcpolygons.size(); i ++)
		{
			*finalCloud += *pcpolygons.at(i)->getCloud();
			saveCloud("pol" + ofToString(pcpolygons.at(i)->getPolygonModelObject()->getName()) + ".pcd", *pcpolygons.at(i)->getCloud());
		}
		saveCloud("finalCloud" + ofToString(getId()) + ".pcd", *finalCloud);

		setCloud(finalCloud);
		pcPolygonsMutex.unlock();

	}
Exemplo n.º 2
0
int AbsFlux6 (StisInfo6 *sts, RowContents *out,
              PhotInfo *phot, PhotInfo *photc, ApInfo *slit, TdsInfo *tds,
              CTICorrInfo *cti, double hfactor, double atodgain, int optimal,
              double *pfactor, double *blazeshift)
{

    /* arguments:
       StisInfo6 *sts         i: calibration switches and info
       RowContents *out       io: output data
       PhotInfo *phot         i: photometry info
       PhotInfo *photc        i: for extraction box height correction
       ApInfo *slit           i: slit info (for throughput)
       TdsInfo *tds           i: time-dependent sensitivity info
       double hfactor         i: divide to convert back to observed wavelength
       double atodgain        i: CCD ATODGAIN value
       int optimal            i: is optimal extraction ?
       double *pfactor;       i: flux normalization factor from opt. extr.
                                 profile
       double *blazeshift;    o: blaze shift value actually used
    */

        double wl;              /* observed wavelength at a pixel */
        double response;        /* instrumental response at a wavelength */
        double pct_factor;      /* correction to infinite extr box height */
        double pct_factor2;     /* correction for current extr box height */
        double tds_factor;      /* correction for time-dependent sens. */
        double gac_factor;      /* grating-aperture correction */
        double throughput;      /* factor to correct for slit throughput */
        double photfactor;      /* to get inverse sensitivity */
        double dispersion;      /* dispersion in A/pix */
        float correction;       /* combined correction factor */
        float ecorrection;      /* combined correction factor for the error */
        int i;
        int status;
        int abs_starti;         /* index to begin search in interp1d */
        int pct_starti;
        int thr_starti;
        int gac_starti;
        int tds_starti;
        double hf;
        double *tds_factors;    /* array with time-dependent sensitivity
                                   correction factors */
        double *wl_no_blaze;    /* phot->wl before blaze shift correction */

        void BlazeCorr (PhotInfo *, double, double, int, double, double *,
                        double);
        void TdsCorrection (TdsInfo *, double, double, double *);

        abs_starti = 1;                         /* initial values */
        pct_starti = 1;
        thr_starti = 1;
        gac_starti = 1;
        tds_starti = 1;

        /* Get the CCD halo factor (haloterm), for opt_elem G750L or G750M. */
        cti->allocated = 0;
        if ((status = getHalo (sts,
                out->npts, out->wave, out->net, cti)) != 0) {
            return (status);
        }

        photfactor = H_PLANCK * C_LIGHT / HST_AREA;

        if (sts->heliocorr == PERFORM)
            hf = sts->hfactor;
        else
            hf = 1.0;

        /* Generate time-dependent sensitivity correction factors. */
        if (sts->tdscorr == PERFORM) {
            tds_factors = (double *) malloc (tds->nwl * sizeof (double));
            if (tds_factors == NULL)
                return (OUT_OF_MEMORY);

            TdsCorrection (tds, sts->expstart, sts->detector_temp,
                           tds_factors);
        }

        /* Apply MSM/blaze correction to throughput array. Dispersion
           is required in the case the reference values from the _pht
           table are invalid, AND we are passing a blazeshift value
           thru the command line. In this case, we use the dispersion
           at the mid point in the current spectral order.

           First we have to save the phot->wl array, because when we
           interpolate to get pct_factor we must use wavelengths that
           do not include the blaze shift correction.
        */
        wl_no_blaze = malloc (phot->nelem * sizeof (double));
        if (wl_no_blaze == NULL)
            return (OUT_OF_MEMORY);
        for (i = 0;  i < phot->nelem;  i++)
            wl_no_blaze[i] = phot->wl[i];

        if (phot->wpos != 0.0 || sts->blazeshift != NO_VALUE) {

            i = out->npts / 2;
            dispersion = getDispersion (out, i);
            dispersion /= hf;

            BlazeCorr (phot, sts->expstart, sts->expend, out->sporder,
                       sts->blazeshift, blazeshift, dispersion);
        }

        /* Loop over flux array. */
        for (i = 0; i < out->npts; i++) {

            /* Convert back to observed wavelength. */
            wl = out->wave[i] / hfactor;

            /* Interpolate in the reference tables. */
            response    = extrap1d (wl, phot->wl, phot->thru, phot->nelem,
                                    &abs_starti);
            pct_factor  = interp1d (wl, wl_no_blaze, phot->pcorr, phot->nelem,
                                    &pct_starti);
            pct_factor2 = interp1d (wl, photc->wl, photc->pcorr, photc->nelem,
                                    &pct_starti);
            throughput  = interp1d (wl, slit->wl, slit->thr, slit->nelem,
                                    &thr_starti);
            if (sts->gaccorr == PERFORM) {
                gac_factor = interp1d (wl, slit->gac_wl, slit->gac_thr,
                                slit->gac_nelem, &gac_starti);
            } else {
                gac_factor = 1.;
            }
            if (sts->tdscorr == PERFORM)
                tds_factor  = interp1d (wl, tds->wl, tds_factors,
                                        tds->nwl, &tds_starti);
            else
                tds_factor = 1.;

            /* Check for zeroed throughput (OPR 38749) */
            if (throughput <= 0.0) {
                out->flux[i]  = 0.0F;
                out->error[i] = 0.0F;
                out->dq[i]   |= CALIBDEFECT;
                continue;
            }

            /* Compute dispersion at current pixel. */

            dispersion = getDispersion (out, i);

            if (dispersion <= 0.0) {
                out->flux[i]  = 0.0F;
                out->error[i] = 0.0F;
                out->dq[i]   |= CALIBDEFECT;
                continue;
            }
            dispersion /= hf;

            /* Compute flux. */

            if (response <= 0.0) {
                out->flux[i]  = 0.0F;
                out->error[i] = 0.0F;
                out->dq[i]   |= CALIBDEFECT;
            } else {
                float qfactor = 1.0;
                float net   = out->net[i];

                correction = (float) (photfactor / (response * throughput *
                                      wl * dispersion * CM_PER_ANGSTROM));
                correction *= atodgain;  /* added 9/3/97 (IB) */
                correction *= pct_factor / pct_factor2;
                correction /= gac_factor;
                correction /= tds_factor;
                ecorrection = correction;

                if (sts->detector == CCD_DETECTOR) {
                    qfactor = QFactor(sts, wl, out->extrsize, out->gross[i]);
                    if (sts->ctecorr == PERFORM) {
                        if (out->gross[i] > 0.0) {
                            net = out->gross[i] *
                                CtiCorr(sts, cti, cti->haloterm[i],
                                        out->extrsize, out->extrlocy[i],
                                        out->gross[i], out->back[i])
                                - out->back[i];
                        } else {
                            out->dq[i] |= NOT_CTI_CORR;
                        }
                    }
                }
                if (optimal)
                    correction *= pfactor[i];
                if (ecorrection <= 0.) {
                    out->flux[i]  = 0.0F;
                    out->error[i] = 0.0F;
                    out->dq[i]   |= CALIBDEFECT;
                } else {
                    out->flux[i] = net * correction;
                    out->error[i] *= ecorrection * qfactor;
                    out->net_error[i] *= qfactor;
                }
            }
        }

        if (sts->tdscorr == PERFORM)
            free (tds_factors);

        if (cti->allocated)
            free (cti->haloterm);

        free (wl_no_blaze);

        return (0);
}