Exemplo n.º 1
0
int main()
{
    init();
#ifdef TIME
    printf("Function: %s\tCPC = %.2f\n", "simple", cpt(test_simple, val));
    printf("Function: %s\tCPC = %.2f\n", "simple_l", cpt(test_simple_l, val));
#endif
    return 0;
}
Exemplo n.º 2
0
void run_tests(test_funct tf, char *descr)
{
  printf("Function: %s\t  div(+,   -)\tCPD = %.2f\n", descr,
	 cpt(tf, POS_VAL, NEG_VAL, 0));
  printf("Function: %s\t cdiv(+,   -)\tCPD = %.2f\n", descr,
	 cpt(tf, POS_VAL, NEG_VAL, 1));
  printf("Function: %s\t cdiv(-,   +)\tCPD = %.2f\n", descr,
	 cpt(tf, NEG_VAL, POS_VAL, 1));
  printf("Function: %s\t cdiv(+, a+-)\tCPD = %.2f\n", descr,
	 cpt(tf, POS_VAL, AMIX_VAL, 1));
  printf("Function: %s\t cdiv(+, r+-)\tCPD = %.2f\n", descr,
	 cpt(tf, POS_VAL, RMIX_VAL, 1));
}
Exemplo n.º 3
0
size_t		ft_strlcat(char *dst, const char *src, size_t size)
{
	char		*dst_temp;
	const char	*src_temp;
	size_t		i;
	size_t		dst_len;

	dst_temp = dst;
	src_temp = src;
	i = size;
	cpt(&dst_temp, &i);
	dst_len = ft_strlen(dst) - ft_strlen(dst_temp);
	i = size - dst_len;
	if (i == 0)
		return (ft_strlen(src_temp) + dst_len);
	while (*src_temp != '\0')
	{
		if (i != 1)
		{
			*dst_temp = *src_temp;
			dst_temp++;
			i--;
		}
		src_temp++;
	}
	*dst_temp = '\0';
	return (ft_strlen(src) - ft_strlen(src_temp) + dst_len);
}
Exemplo n.º 4
0
static void
test_hetero_move_assign ()
{
    rw_info (0, __FILE__, __LINE__,
             "move assignment operator (heterogenous tuples)");

    int i = std::rand () % CHAR_MAX;

    std::tuple<char> cit (i);
    std::tuple<int> it;
    it = std::move (cit);
    test (__LINE__, it, i);

    std::tuple<unsigned, String> cpt (12345U, "string");
    std::tuple<long, const char*> pt;
    pt = std::move (cpt);
    test (__LINE__, pt, 12345U, (const char*) "string");

    char s [] = "string"; const UserDefined ud (i);
    std::tuple<int, int, short, float, char*, UserDefined>
        cbt (int (true), int ('a'), short (i), 3.14159f, s, ud);
    std::tuple<bool, char, int, double, void*, UserDefined> bt;
    ++UserDefined::expect.move_ctor;
    UserDefined::reset ();
    bt = std::move (cbt);  ++UserDefined::expect.move_asgn;
    test (__LINE__, bt, true, 'a', i, 3.14159f, s, ud);
}
Exemplo n.º 5
0
static AcGePoint3d FindClosePoint( const AcGePoint3dArray& pts, const AcGePoint3d& pt )
{
    AcGePolyline3d pline( pts );

    AcGePoint3d cpt( pt );
    return pline.closestPointTo( pt );
}
Exemplo n.º 6
0
/*--------------------------------------------------------------------------*/
IsotimeEpoch _isotime2epoch(const char * isotime_s) 
{ char osign_c;
  long osign;
  long year=0, month=0, day=0, hh=0, mm=0, ss=0;
  long Hh=0, Mm=0, Ss=0;
  double uuuuuu=0.0;
  char trimmed[TRIMLEN], *pd, *pt, *pf, *po, *pr;
  char datbuf[DLEN];
  char timbuf[TLEN];
  char frabuf[FLEN];
  char offbuf[OLEN];
  IsotimeEpoch epoch;

  if (ISOTIME_debug>0) fprintf(stderr,"_isotime2epoch >>%s<< BEGIN\n",
    isotime_s);

  // trim isotime_s, convert to uppercase and copy to trimmed
  pd = trim( trimmed, TRIMLEN, isotime_s );
  if (ISOTIME_debug>1) fprintf(stderr," trim returns >>%s<<\n",pd);

  // copy date
  pt = cpd( datbuf, DLEN, pd );
  if (ISOTIME_debug>1) fprintf(stderr," date >>%s<<\n",datbuf);

  // copy time
  pf = cpt( timbuf, TLEN, pt );
  if (ISOTIME_debug>1) fprintf(stderr," time >>%s<<\n",timbuf);

  // copy fraction
  po = cpf( frabuf, FLEN, pf );
  if (ISOTIME_debug>1) fprintf(stderr," fraction >>%s<<\n",frabuf);

  // copy offset
  pr = cpo( offbuf, OLEN, po );
  if (ISOTIME_debug>1) fprintf(stderr," offset >>%s<<\n",offbuf);
  
  sscanf(datbuf,"%4ld%2ld%2ld",&year,&month,&day);
  sscanf(timbuf,"%2ld%2ld%2ld",&hh,&mm,&ss);
  sscanf(frabuf,"%lf",&uuuuuu);
  sscanf(offbuf,"%c%2ld%2ld%2ld",&osign_c,&Hh, &Mm, &Ss);

  if ( strlen(pr)||(day==0) ) month=0; // error, if rest is not empty or day 0

  osign = (osign_c=='-')?-1:+1;
  epoch =  _convert2epoch(year,month,day,hh,mm,ss,uuuuuu,osign,Hh,Mm,Ss);

  if ( epoch.status ) {
    fprintf( stderr, "ERROR: Cannot read time \"%s\"\n",trimmed );
    fprintf( stderr, "       Format: YYYY-MM-DDThh:mm:ss[.uuuuuu][+Hh:Mm]\n" );
  }

  if (ISOTIME_debug>0) fprintf(stderr,"_isotime2epoch >>%s<< END\n",
    isotime_s);

  return( epoch );

} // _isotime2epoch
Exemplo n.º 7
0
int
main()
{
	int np = 0 ;
	cpt();
	printf("ok");
	if (! np++)
		longjmp(buf,~0);
	printf("np = %d\n", np );
	printf("i = %d\n", i );
}
Exemplo n.º 8
0
void test_dispatcher()
{
    RefCountedPtr<SysContext> ctx(new SysContext);
    RefCountedPtr<iSysComponent> cpt( new StdLogger( StdLogger::LOGC_DEBUG) );
    ctx->addComponent( cpt );

    // create the interfaces
    RefCountedPtr<RpcInterface> intf( new RpcInterface( NTEXT("interface"), ctx ));
    RefCountedPtr<RpcInterface> intf1( new RpcInterface( NTEXT("interface"), ctx ));
    RefCountedPtr<RpcInterface> intf2( new RpcInterface( NTEXT("interface"), ctx ));
 
    // create the methods
    RefCountedPtr<Object1Method1> method( 
        new Object1Method1(NTEXT("method"), NTEXT("default")) );
    intf->addMethod( (RefCountedPtr<iRpcMethod>&)method );

    RefCountedPtr<Object1Method1> method1( 
        new Object1Method1(NTEXT("method"), NTEXT("apache")) );
    intf1->addMethod( (RefCountedPtr<iRpcMethod>&)method1 );

    RefCountedPtr<Object1Method1> method2( 
        new Object1Method1(NTEXT("method"), NTEXT("cslib")) );
    intf2->addMethod( (RefCountedPtr<iRpcMethod>&)method2 );

    RpcDispatcher disp( NTEXT("test-dispatcher"), ctx );
    disp.addInterface( intf );
    disp.addInterface( intf1, APACHE_TENANT );
    disp.addInterface( intf2, CSLIB_TENANT );

    DOMDocument* requestDoc = DomUtils::getDocument( NTEXT("rpc_dispatcher.xml") );
    if (requestDoc != NULL)
    {
        StreamFormatTarget targ(COUT);

        DOMDocument* responseDoc = DomUtils::createDocument( NTEXT("default") );
	if (responseDoc != NULL)
	{
	    disp.dispatch( requestDoc, responseDoc );
	    disp.dispatch( requestDoc, responseDoc, APACHE_TENANT );
	    disp.dispatch( requestDoc, responseDoc, CSLIB_TENANT );
	    disp.dispatch( requestDoc, responseDoc, INVALID_TENANT );
	  
	    DomUtils::print( responseDoc, NTEXT("UTF-8"), targ );

	    responseDoc->release();
	}

	requestDoc->release();
    }
}
Exemplo n.º 9
0
void ComputeUnaryPairwiseSums(CFVoxel *fgU, CFVoxel *bgU, 
							  CTypedPtrArray<CPtrArray, CFVoxel*> &pw, cvPoint3iArray &pwnc, int idx,
							  CVoxel *segm, double &usum, double &pwsum)
{
	int imX = segm->m_nX;
	int imY = segm->m_nY;
	int imZ = segm->m_nZ;
	usum = 0;
	pwsum = 0;
	gtype fgusum, bgusum;
	fgusum = bgusum = 0;
	int x, y, z, i, n, l;
	int nn = (int) pwnc.GetSize();
	cv::Point3i dpt(imX, imY, imZ);
	for ( z = 0, i = 0; z < imZ; z++ ) {
		for ( y = 0; y < imY; y++ ) {
			for ( x = 0; x < imX; x++, i++ ) {
				// get label of current pixel
				l = segm->m_pData[i];
				//////////////////////////////////////////////////////////////////////////
				// sum unary and pairwise energy from labels and potentials
				// UNARY energy
				// if voxel is assigned as background, add bgUnaries
				if ( l == 0 )
					bgusum += bgU->m_pfData[i];
				// else, add fgUnaries
				else 
					fgusum += fgU->m_pfData[i];

				// PAIRWISE energy
				// for all neighbors 
				cv::Point3i cpt(x,y,z);
				for ( n = 0; n < nn; n++ ) {
					cv::Point3i pt = cpt+pwnc[n];
					if ( ZERO_3DPT <= pt && pt < dpt  && 
						l != segm->m_pData[pt.m_z*imX*imY+pt.m_y*imX+pt.m_x] ) {
						//CFVoxel* tmpPW = pw[idx*nn + n];
						pwsum += pw[idx*nn + n]->GetAt(x,y,z);
					}
						
				}
			} // end for x
		} // end for y
	} 
	usum = fgusum+bgusum;
}
Exemplo n.º 10
0
TEST (test_person, test_list_employees)
{
	Person jlp("Jean Luc Piccard");
	Person wc("Wesley Crusher");

	Employer emp1("Star Fleet Federation", "galaxy");
	Position cpt("captain", "the big boss");
	Position lieut("lieutenant", "second in command");

	emp1.hire(jlp, cpt);
	emp1.hire(wc, lieut);

	EXPECT_EQ(emp1.getNbEmployees(), 2);

	EXPECT_STREQ(jlp.getEmployer().c_str(), emp1.getName().c_str());
	EXPECT_STREQ(wc.getEmployer().c_str(), emp1.getName().c_str());
}
Exemplo n.º 11
0
Assignment
get_nearest_assignment(const Subset &s,
                       const algebra::VectorKD &embedding,
                       ParticleStatesTable *pst) {

  Ints ret(s.size());
  unsigned int cur=0;
  // kind of a hack to get size
  for (unsigned int i=0; i< s.size(); ++i) {
    unsigned int sz
        = pst->get_particle_states(s[i])->get_embedding(0).get_dimension();
    algebra::VectorKD cpt(embedding.coordinates_begin()+cur,
                          embedding.coordinates_begin()+cur+sz);
    cur+=sz;
    ret[i]= pst->get_particle_states(s[i])->get_nearest_state(cpt);
  }
  return Assignment(ret);
}
Exemplo n.º 12
0
double C3DPoint::GetNearestShellDistance( CVoxelShell* bci)
{
	int nPt = bci->npts;

	double* dist = new double[nPt];
	double minVal = FLT_MAX;
	int minIdx;
	for ( int i = 0; i < nPt; i++ ) {
		C3DPoint cpt(m_x,m_y,m_z);
		dist[i] = VectorL2Dist( cpt, bci->pts[i]);
		if ( dist[i] < minVal ) {
			minVal = dist[i];
			minIdx = i;
		}
	}

	SAFE_DELETE_ARRAY(dist);
	return minVal;
}
Exemplo n.º 13
0
static void
test_hetero_copy_ctor ()
{
    rw_info (0, __FILE__, __LINE__,
             "copy constructor (heterogenous tuples)");

    int i = std::rand () % CHAR_MAX;

    const std::tuple<char> cit (static_cast<char> (i));
    std::tuple<int> it (cit);
    test (__LINE__, it, i);

    std::tuple<unsigned, String> cpt (12345U, "string");
    std::tuple<long, const char*> pt (cpt);
    test (__LINE__, pt, 12345U, (const char*) "string");

    char s [] = "string"; const UserDefined ud (i);
    const std::tuple<int, int, short, float, char*, UserDefined>
        cbt (int (true), int ('a'), short (i), 3.14159f, s, ud);
    UserDefined::reset ();
    std::tuple<bool, char, int, double, void*, UserDefined> bt (cbt);
    ++UserDefined::expect.copy_ctor;
    test (__LINE__, bt, true, 'a', i, 3.14159f, s, ud);
}
int main(int argc, char **argv)
{
	count_loops = 0;	

	ros::init(argc, argv, "convertimagefromHTPApublished");
	ros::NodeHandle n;
	
	ros::param::set("zoom", 20);
	//lower_limit = 25;	
 	//upper_limit = 45;
 	
	zoom = 20;
	
	HTPAimage = cvCreateImage(cvSize(32*zoom,31*zoom),IPL_DEPTH_8U,3);	
 
 	image_transport::ImageTransport it(n);
  	image_transport::Publisher HTPAimage_pub = it.advertise("HTPAimage", 1);
 
        //ros::Subscriber sub = n.subscribe("HTPAoutput", 1000, HTPAoutputCallback);
        ros::Subscriber sub = n.subscribe("HTPAoutput", 0, HTPAoutputCallback);
        
  dynamic_reconfigure::Server<heiman::convertimagefromHTPApublishedConfig> server;
  dynamic_reconfigure::Server<heiman::convertimagefromHTPApublishedConfig>::CallbackType f;
  
  f = boost::bind(&config_callback, _1, _2);
  server.setCallback(f);   

	ros::Rate loop_rate(10);
	cv::namedWindow(WINDOW);
	while (ros::ok())
	  {
			count_loops++;
			if (count_loops == 100) 
			{
				ROS_WARN("Ten seconds without new HTPA output published");
				count_loops = 0;
			}
			
		int zoom_aux;	
		ros::param::get("zoom", zoom_aux);
		//if (ros::param::has("lower_limit"))
			//ros::param::get("lower_limit", lower_limit);		
		//if (ros::param::has("upper_limit"))
			//ros::param::get("upper_limit", upper_limit);		
		
 		if (zoom_aux != zoom)
		{
			zoom = zoom_aux;
			cvReleaseImage(&HTPAimage);
			HTPAimage = cvCreateImage(cvSize(32*zoom,31*zoom),IPL_DEPTH_8U,3);	 		
		}
	    // Eli
		//cv_bridge::CvImage cvi;
		cv_bridge::CvImagePtr cpt(new cv_bridge::CvImage);
		ros::Time time = ros::Time::now();
		//cvi.header.stamp = time;
		//cvi.header.frame_id = "image";
		//cvi.encoding = "bgr8";
		//cvi.image = HTPAimage;
		cpt->header.stamp = time;
		cpt->header.frame_id = "image";
		cpt->encoding = "bgr8";
		cpt->image = HTPAimage; //HTPAimage;
		//cv::imshow(WINDOW, cpt->image);
		//cv::waitKey(3);
		//sensor_msgs::Image msg; //Needs to be ImageConstPtr ???
		//cvi.toImageMsg(msg);
		//cpt->toImageMsg(msg);
		HTPAimage_pub.publish(cpt->toImageMsg()); //msg);
	    //sensor_msgs::ImagePtr msg = sensor_msgs::cv_bridge::cvToImgMsg(HTPAimage, "bgr8");
	    //HTPAimage_pub.publish(msg);
	    //------
			
	    ros::spinOnce();

	    loop_rate.sleep();
	  }


	return 0;
}
Exemplo n.º 15
0
void Egal_field_correct_ite(string aDir,std::vector<std::string> * aSetIm, cl_MatPtsHom aMatPtsHomol , string aDirOut, string InVig, int ResolModel, int nbIm, int nbIte, double aThresh)
{
//truc à iterer--------------------------------------------------------------------------------------------------------------------------------------
for(int iter=0;iter<nbIte;iter++){
    cout<<"Pass "<<iter+1<<" out of "<< nbIte<<endl;

    //Filtering the tie points
    aMatPtsHomol = TiePtsFilter(aMatPtsHomol, aThresh);

//Correcting the tie points

//#pragma omp parallel for

    for(int numImage1=0;numImage1<nbIm;numImage1++)
    {
        vector<int> cpt(nbIm,0);
        cout<<"Computing factors for Im "<<numImage1<<endl;

        //For each tie point point, compute correction value (distance-ponderated mean value of all the tie points)
        for(int k = 0; k<int(aMatPtsHomol.aMat[numImage1].size()) ; k++){//go through each tie point
            double aCorR=0.0,aCorG=0.0,aCorB=0.0;
            double aSumDist=0;
            Pt2dr aPt(aMatPtsHomol.aMat[numImage1].Pts[k].x/ResolModel,aMatPtsHomol.aMat[numImage1].Pts[k].x/ResolModel);
            for(int numPt = 0; numPt<int(aMatPtsHomol.aMat[numImage1].size()) ; numPt++){//go through each tie point
                Pt2dr aPtIn(aMatPtsHomol.aMat[numImage1].Pts[numPt].x/ResolModel,aMatPtsHomol.aMat[numImage1].Pts[numPt].y/ResolModel);
                double aDist=euclid(aPtIn, aPt);
                if(aDist<1){aDist=1;}
                aSumDist=aSumDist+1/(aDist);
                aCorR = aCorR + aMatPtsHomol.aMat[numImage1].kR[numPt]/(aDist);
                aCorG = aCorG + aMatPtsHomol.aMat[numImage1].kG[numPt]/(aDist);
                aCorB = aCorB + aMatPtsHomol.aMat[numImage1].kB[numPt]/(aDist);
            }
            //Normalize
            aCorR = aCorR/aSumDist;
            aCorG = aCorG/aSumDist;
            aCorB = aCorB/aSumDist;

            //correcting Tie points color with computed surface
            //int numImage2=aMatPtsHomol.aMat[numImage1].OtherIm[k];
            //int pos=cpt[numImage2];cpt[numImage2]++;
            //if(aMatPtsHomol.aMat[numImage1][numImage2].R1[pos]*aCorR>255)
            //{
            //	aCorR=255/aMatPtsHomol.aMat[numImage1][numImage2].R1[pos];
            //}
            //if(aMatPtsHomol.aMat[numImage1][numImage2].G1[pos]*aCorB>255)
            //{
            //	aCorG=255/aMatPtsHomol.aMat[numImage1][numImage2].G1[pos];
            //}
            //if(aMatPtsHomol.aMat[numImage1][numImage2].B1[pos]*aCorG>255)
            //{
            //	aCorB=255/aMatPtsHomol.aMat[numImage1][numImage2].B1[pos];
            //}
            aMatPtsHomol.aMat[numImage1].kR[k]=aCorR;
            aMatPtsHomol.aMat[numImage1].kG[k]=aCorG;
            aMatPtsHomol.aMat[numImage1].kB[k]=aCorB;
            }
        //cout<<cpt<<endl;

    }
}

//Filtering the tie points
aMatPtsHomol = TiePtsFilter(aMatPtsHomol, aThresh);

cout<<"Factors were computed"<<endl;
//end truc à iterer--------------------------------------------------------------------------------------------------------------------------------------



//Applying the correction to the images
    //Bulding the output file system
    ELISE_fp::MkDirRec(aDir + aDirOut);
    //Reading input files
    string suffix="";if(InVig!=""){suffix="_Vodka.tif";}


#ifdef USE_OPEN_MP
#pragma omp parallel for
#endif
    for(int i=0;i<nbIm;i++)
    {
        string aNameIm=InVig + (*aSetIm)[i] + suffix;//if vignette is used, change the name of input file to read
        cout<<"Correcting "<<aNameIm<<" (with "<<aMatPtsHomol.aMat[i].size()<<" data points)"<<endl;
        string aNameOut=aDir + aDirOut + (*aSetIm)[i] +"_egal.tif";

        Pt2di aSzMod=aMatPtsHomol.aMat[i].SZ;//Size of the correction surface, taken from the size of the scaled image
        //cout<<"aSzMod"<<aSzMod<<endl;
        Im2D_REAL4  aImCorR(aSzMod.x,aSzMod.y,0.0);
        Im2D_REAL4  aImCorG(aSzMod.x,aSzMod.y,0.0);
        Im2D_REAL4  aImCorB(aSzMod.x,aSzMod.y,0.0);
        REAL4 ** aCorR = aImCorR.data();
        REAL4 ** aCorG = aImCorG.data();
        REAL4 ** aCorB = aImCorB.data();
        //cout<<vectPtsRadioTie[i].size()<<endl;
        //For each point of the surface, compute correction value (distance-ponderated mean value of all the tie points)
        long start=time(NULL);
        for (int aY=0 ; aY<aSzMod.y  ; aY++)
            {
                for (int aX=0 ; aX<aSzMod.x  ; aX++)
                {
                    float aCorPtR=0,aCorPtG=0,aCorPtB=0;
                    double aSumDist=0;
                    Pt2dr aPt(aX,aY);
                    for(int j = 0; j<int(aMatPtsHomol.aMat[i].size()) ; j++){//go through each tie point
                        Pt2dr aPtIn(aMatPtsHomol.aMat[i].Pts[j].x/ResolModel,aMatPtsHomol.aMat[i].Pts[j].y/ResolModel);
                        double aDist=euclid(aPtIn, aPt);
                        if(aDist<1){aDist=1;}
                        aSumDist=aSumDist+1/(aDist);
                        aCorPtR = aCorPtR + aMatPtsHomol.aMat[i].kR[j]/(aDist);
                        aCorPtG = aCorPtG + aMatPtsHomol.aMat[i].kG[j]/(aDist);
                        aCorPtB = aCorPtB + aMatPtsHomol.aMat[i].kB[j]/(aDist);
                    }
                    //Normalize
                    aCorR[aY][aX] = aCorPtR/aSumDist;
                    aCorG[aY][aX] = aCorPtG/aSumDist;
                    aCorB[aY][aX] = aCorPtB/aSumDist;
                }
            }

        long end = time(NULL);
        cout<<"Correction field computed in "<<end-start<<" sec, applying..."<<endl;

        //Reading the image and creating the objects to be manipulated
        Tiff_Im aTF= Tiff_Im::StdConvGen(aDir + aNameIm,3,false);
        Pt2di aSz = aTF.sz();

        Im2D_U_INT1  aImR(aSz.x,aSz.y);
        Im2D_U_INT1  aImG(aSz.x,aSz.y);
        Im2D_U_INT1  aImB(aSz.x,aSz.y);

        ELISE_COPY
        (
           aTF.all_pts(),
           aTF.in(),
           Virgule(aImR.out(),aImG.out(),aImB.out())
        );

        U_INT1 ** aDataR = aImR.data();
        U_INT1 ** aDataG = aImG.data();
        U_INT1 ** aDataB = aImB.data();

        for (int aY=0 ; aY<aSz.y  ; aY++)
            {
                for (int aX=0 ; aX<aSz.x  ; aX++)
                {
                    Pt2dr aPt(double(aX/ResolModel),double(aY/ResolModel));
                    //To be able to correct the edges
                        if(aPt.x>aSzMod.x-2){aPt.x=aSzMod.x-2;}
                        if(aPt.y>aSzMod.y-2){aPt.y=aSzMod.y-2;}
                    //Bilinear interpolation from the scaled surface to the full scale image
                    double R = aDataR[aY][aX]*Reechantillonnage::biline(aCorR, aSzMod.x, aSzMod.y, aPt);
                    double G = aDataG[aY][aX]*Reechantillonnage::biline(aCorG, aSzMod.x, aSzMod.y, aPt);
                    double B = aDataB[aY][aX]*Reechantillonnage::biline(aCorB, aSzMod.x, aSzMod.y, aPt);
                    //Overrun management:
                    if(R>255){aDataR[aY][aX]=255;}else if(R<0){aDataR[aY][aX]=0;}else{aDataR[aY][aX]=R;}
                    if(G>255){aDataG[aY][aX]=255;}else if(G<0){aDataG[aY][aX]=0;}else{aDataG[aY][aX]=G;}
                    if(B>255){aDataB[aY][aX]=255;}else if(B<0){aDataB[aY][aX]=0;}else{aDataB[aY][aX]=B;}
                }
        }


        //Writing ouput image
         Tiff_Im  aTOut
            (
                aNameOut.c_str(),
                aSz,
                GenIm::u_int1,
                Tiff_Im::No_Compr,
                Tiff_Im::RGB
            );


         ELISE_COPY
             (
                 aTOut.all_pts(),
                 Virgule(aImR.in(),aImG.in(),aImB.in()),
                 aTOut.out()
             );

    }
}
Exemplo n.º 16
0
void
ColorTableAttributes::SetFromNode(DataNode *parentNode)
{
    if(parentNode == 0)
        return;

    DataNode *searchNode = parentNode->GetNode("ColorTableAttributes");
    if(searchNode == 0)
        return;

    // Look for the number of color tables.
    DataNode *node = 0;
    if((node = searchNode->GetNode("Ntables")) != 0)
    {
        char tmp[100];
        int  ntables = node->AsInt();

        // Look for ntables color table nodes.
        for(int i = 0; i < ntables; ++i)
        {
            SNPRINTF(tmp, 100, "table%02d", i);
            if((node = searchNode->GetNode(tmp)) != 0)
            {
                DataNode *nameNode = node->GetNode("ctName");
                DataNode *pointNode = node->GetNode("controlPts");

                // If we have the name node and the pointNode, we can add a
                // color table.
                if(nameNode && pointNode)
                {
                    ColorControlPointList ccpl;

                    // Try and set the equal flag.
                    DataNode *tmpNode;
                    if((tmpNode = node->GetNode("equal")) != 0)
                        ccpl.SetEqualSpacingFlag(tmpNode->AsBool());
                    // Try and set the smooth flag.
                    if((tmpNode = node->GetNode("smooth")) != 0)
                        ccpl.SetSmoothingFlag(tmpNode->AsBool());
                    if((tmpNode = node->GetNode("discrete")) != 0)
                        ccpl.SetDiscreteFlag(tmpNode->AsBool());

                    // Set the color control points.
                    floatVector fvec = pointNode->AsFloatVector();
                    for(size_t j = 0; j < fvec.size() / 4; ++j)
                    {
                        // Create a control point based on the values
                        // in the float vector.
                        int index = j * 4;
                        ColorControlPoint cpt(fvec[index],
                                              (unsigned char)(fvec[index+1]),
                                              (unsigned char)(fvec[index+2]),
                                              (unsigned char)(fvec[index+3]),
                                              255);
                        ccpl.AddControlPoints(cpt);
                    }

                    // If the color table is already in the list, remove it.
                    // Then add the new color table to the list.
                    RemoveColorTable(nameNode->AsString());
                    AddColorTable(nameNode->AsString(), ccpl);
                }
            }
        } // end for i
    }

    if((node = searchNode->GetNode("activeContinuous")) != 0)
        SetActiveContinuous(node->AsString());

    if((node = searchNode->GetNode("activeDiscrete")) != 0)
        SetActiveDiscrete(node->AsString());

    // For older version compatibility...
    if((node = searchNode->GetNode("activeColorTable")) != 0)
        SetActiveContinuous(node->AsString());
}
Exemplo n.º 17
0
// ######################################################################
Image<float> ContourBoundaryDetector::getContourBoundaryEdgels()
{
  // NOTE: FIXXXX: TENSOR-VOTING IS PROBABLY A BETTER IDEA

  int w = itsImage.getWidth();
  int h = itsImage.getHeight();
  Image<float> edgelBoundaryImage(w,h,ZEROS);

  int step  = BOUNDARY_STEP_SIZE;
  int hstep = step/2;
  //int wSize = BOUNDARY_STEP_SIZE+1;

  // set up the center and surround opponency locations
  std::vector<std::vector<Point2D<int> > > cCoords(NUM_RIDGE_DIRECTIONS);
  std::vector<std::vector<Point2D<int> > > sCoords(NUM_RIDGE_DIRECTIONS);
  std::vector<float> angles;

  for(uint k = 0; k < NUM_RIDGE_DIRECTIONS; k++)
    {
      cCoords[k] = std::vector<Point2D<int> >();  
      sCoords[k] = std::vector<Point2D<int> >();  

      angles.push_back(k*2.0*M_PI/float(NUM_RIDGE_DIRECTIONS));
    }

  // fill the center coordinates
  for(int i = -step/2; i < step/2; i++)
    {
      cCoords[0].push_back(Point2D<int>( i, 0));
      cCoords[1].push_back(Point2D<int>( i, i));
      cCoords[2].push_back(Point2D<int>( 0, i));
      cCoords[3].push_back(Point2D<int>( i,-i));
    }

  // fill the surround coordinates (bottom or right)
  for(int i = 0; i < hstep; i++)
    {
      sCoords[0].push_back(Point2D<int>( i+hstep,       0));
      sCoords[0].push_back(Point2D<int>( i+hstep,   hstep));
      sCoords[0].push_back(Point2D<int>( i+hstep,  -hstep));

      sCoords[1].push_back(Point2D<int>( i+hstep, i+hstep));
      sCoords[1].push_back(Point2D<int>( i+step , i      ));
      sCoords[1].push_back(Point2D<int>( i      ,-i-step ));

      sCoords[2].push_back(Point2D<int>(       0, i+hstep));
      sCoords[2].push_back(Point2D<int>(   hstep, i+hstep));
      sCoords[2].push_back(Point2D<int>(  -hstep, i+hstep));

      sCoords[3].push_back(Point2D<int>( i+hstep,-i-hstep));
      sCoords[3].push_back(Point2D<int>( i      ,-i-step ));
      sCoords[3].push_back(Point2D<int>( i+step ,-i      ));
    }

  // fill the surround coordinates (top or left)
  for(int i = -hstep; i < 0; i++)
    {
      sCoords[0].push_back(Point2D<int>( i-hstep,       0));
      sCoords[0].push_back(Point2D<int>( i-hstep,   hstep));
      sCoords[0].push_back(Point2D<int>( i-hstep,  -hstep));

      sCoords[1].push_back(Point2D<int>( i-hstep, i-hstep));
      sCoords[1].push_back(Point2D<int>( i-step , i      ));
      sCoords[1].push_back(Point2D<int>( i      , i-step ));

      sCoords[2].push_back(Point2D<int>(       0, i-hstep));
      sCoords[2].push_back(Point2D<int>(   hstep, i-hstep));
      sCoords[2].push_back(Point2D<int>(  -hstep, i-hstep));

      sCoords[3].push_back(Point2D<int>( i-hstep,-i+hstep));
      sCoords[3].push_back(Point2D<int>( i      ,-i+step ));
      sCoords[3].push_back(Point2D<int>( i-step ,-i      ));
    }

  // reset the edgel storage
  // NOTE: we will keep edgel at index 0 empty
  int wEdgel = (w+hstep)/step; 
  int hEdgel = (h+hstep)/step;
  itsCompleteEdgels = 
    Image<std::vector<rutz::shared_ptr<Edgel> > >(wEdgel, hEdgel, ZEROS);
  itsEdgels = Image<rutz::shared_ptr<Edgel> >(wEdgel, hEdgel, ZEROS);

  // go through each point
  // with the specified step size
  int wLimit = (w/step)*step;
  int hLimit = (h/step)*step;
  for(int j = step; j < hLimit; j+= step)
    {
      for(int i = step; i < wLimit; i+= step)
        {
	  Point2D<int> cpt(i,j);
	  
	  int maxk = -1;
	  Point2D<int> maxPt(-1,-1);
	  float maxVal = -1.0F;

          uint iEdgel = i/step;
          uint jEdgel = j/step;

	  // for each direction
	  for(uint k = 0; k < NUM_RIDGE_DIRECTIONS; k++)
	    {
	      Point2D<int> maxCKpt(-1,-1);
	      float maxCKval = 0.0;

	      // get maximum contour value for the center size
	      // to make the contour detector phase invariant
	      for(uint ci = 0; ci < cCoords[k].size(); ci++)
		{
		  Point2D<int> pt = cCoords[k][ci] + cpt;  
		  if(edgelBoundaryImage.coordsOk(pt)) 
		    {
		      float val = itsRidgeDirectionNMS[k].getVal(pt); 
		      if(maxCKval < val) 
			{
			  maxCKval = val; maxCKpt = pt;
			}
		    }
		}

	      float maxSKval = 0.0;

	      // get the maximum value for the surround 
	      for(uint si = 0; si < sCoords[k].size(); si++)
		{
		  Point2D<int> pt = sCoords[k][si] + cpt;  
		  if(edgelBoundaryImage.coordsOk(pt)) 
		    {
		      float val = itsRidgeDirectionNMS[k].getVal(pt); 
		      if(maxSKval < val) maxSKval = val;
		    }
		}
	      
	      // if center > 0 and wins
	      if(maxCKval > 0.0F && maxCKval > maxSKval)
		{
		  if(maxCKval > maxVal) 
		    {
		      maxPt  = maxCKpt;
		      maxVal = maxCKval;
		      maxk   = k;
		    }
                  
                  // put the new edgel in the right position
                  rutz::shared_ptr<Edgel> 
                    edgel(new Edgel(maxCKpt, angles[k], k, maxCKval)); 
                  
                  std::vector<rutz::shared_ptr<Edgel> >
                    cEdgelList = itsCompleteEdgels.getVal(iEdgel,jEdgel);

                  uint eNum = cEdgelList.size();
                  uint place = 0;
                  for(uint ce = 0; ce < eNum; ce++)
                    {
                      if(cEdgelList[ce]->val < maxCKval)
                        {
                          place = ce; ce = eNum;
                        }
                      else place = ce+1;
                    }
                  //LINFO("place: %d  | eNum: %d", place, eNum);
                  
                  cEdgelList.push_back(edgel);
                  
                  // for(uint ce = 0; ce < cEdgelList.size(); ce++)
                  //   LINFO("%12.5f %3d", cEdgelList[ce]->val,  
                  //         cEdgelList[ce]->angleIndex);

                  if(place != eNum)
                    {
                      // LINFO("move one");
                  
                      for(int ce = int(eNum-1); ce >= int(place); ce--)
                        {
                          cEdgelList[ce+1] = cEdgelList[ce];
                        }
                      
                      // for(uint ce = 0; ce < cEdgelList.size(); ce++)
                      //   LINFO("%12.5f %3d", cEdgelList[ce]->val,  
                      //         cEdgelList[ce]->angleIndex);
                      
                      cEdgelList[place] = edgel;                  
                      
                      // LINFO("place the new one properly");

                      // for(uint ce = 0; ce < cEdgelList.size(); ce++)
                      //   LINFO("%12.5f %3d", cEdgelList[ce]->val,  
                      //         cEdgelList[ce]->angleIndex);
                    }
                  // else LINFO("last place");

                  itsCompleteEdgels.setVal(iEdgel,jEdgel, cEdgelList);


                  // LINFO("%d %d: size: %d ", i,j, 
                  //       int(itsCompleteEdgels.getVal(iEdgel,jEdgel).size()));

                  // for(uint ce = 0; ce < cEdgelList.size(); ce++)
                  //   LINFO("%12.5f %3d", cEdgelList[ce]->val,  
                  //         cEdgelList[ce]->angleIndex);
		}
	    }

	  // if there is a winner
	  if(maxk != -1)
	    {
              itsEdgels.setVal
                (iEdgel,jEdgel, itsCompleteEdgels.getVal(iEdgel,jEdgel)[0]);

	      float borderK = 
		fmod((maxk+(NUM_RIDGE_DIRECTIONS/2)),NUM_RIDGE_DIRECTIONS);

	      float dx = cos(borderK * M_PI/4.0) * hstep; 
	      float dy = sin(borderK * M_PI/4.0) * hstep;

	      Point2D<int> pt = maxPt;
	      Point2D<int> p1 = pt + Point2D<int>( dx+.5,  dy+.5); 
	      Point2D<int> p2 = pt + Point2D<int>(-dx-.5, -dy-.5);

              //uint iEdgel = i/step;
              //uint jEdgel = j/step;
              //if(iEdgel >= 10 && iEdgel <= 25 && jEdgel >= 1 && jEdgel <= 14)
              //   {
              //     LINFO("maxk: %d -> %d  -> %f  %f (%f %f %f %f)  |%f %f", 
              //           maxk, (maxk+(NUM_RIDGE_DIRECTIONS/2)), 
              //           (borderK*M_PI)/float(NUM_RIDGE_DIRECTIONS), borderK, 
              //           cos(0), cos(M_PI/4.0), cos(M_PI/2.0), cos(M_PI*.75),
              //           dx, dy);
	      


              //LINFO("%d %d | %d %d | %d %d::::: %d %d  %d", 
              //         pt.i, pt.j, p1.i, p1.j, p2.i, p2.j, iEdgel, jEdgel, maxk);
                  
              // draw the straightline contour in the image 
              // for visualization
              drawLine(edgelBoundaryImage, p1, p2, 255.0F);
              //drawDisk(edgelBoundaryImage, pt, 2,  255.0F);
              // }      
              
	    }
	}
    }

  return edgelBoundaryImage;
}
Exemplo n.º 18
0
compute(size_t, width)
{
    as(MCHeap);
    size_t height = cpt(height);
    return (size_t)exp2(height-1);
}
void
ColorTableAttributes::SetFromNode(DataNode *parentNode)
{
    if(parentNode == 0)
        return;

    DataNode *searchNode = parentNode->GetNode("ColorTableAttributes");
    if(searchNode == 0)
        return;

    // Look for the number of color tables.
    DataNode *node = 0;
    if((node = searchNode->GetNode("Ntables")) != 0)
    {
        char tmp[100];
        int  ntables = node->AsInt();

        // Look for ntables color table nodes.
        for(int i = 0; i < ntables; ++i)
        {
            SNPRINTF(tmp, 100, "table%02d", i);
            if((node = searchNode->GetNode(tmp)) != 0)
            {
                DataNode *nameNode = node->GetNode("ctName");
                DataNode *pointNode = node->GetNode("controlPts");
                DataNode *colorsHaveOpacity = node->GetNode("colorsHaveOpacity");
                bool readAlpha = false;
                if (colorsHaveOpacity != NULL)
                    readAlpha = true;

                // If we have the name node and the pointNode, we can add a
                // color table.
                if(nameNode && pointNode)
                {
                    ColorControlPointList ccpl;

                    // Try and set the equal flag.
                    DataNode *tmpNode;
                    if((tmpNode = node->GetNode("equal")) != 0)
                        ccpl.SetEqualSpacingFlag(tmpNode->AsBool());
                    // Try and set the smooth flag. (old way)
                    if((tmpNode = node->GetNode("smooth")) != 0)
                        ccpl.SetSmoothing(tmpNode->AsBool()?ColorControlPointList::Linear:ColorControlPointList::None);
                    // (new way)
                    if((tmpNode = node->GetNode("smoothing")) != 0)
                        ccpl.SetSmoothing(static_cast<ColorControlPointList::SmoothingMethod>(tmpNode->AsInt()));

                    if((tmpNode = node->GetNode("discrete")) != 0)
                        ccpl.SetDiscreteFlag(tmpNode->AsBool());

                    if((tmpNode = node->GetNode("category")) != 0)
                        ccpl.SetCategoryName(tmpNode->AsString());
                    else
                        ccpl.SetCategoryName("Standard");

                    // Set the color control points.
                    floatVector fvec = pointNode->AsFloatVector();
                    int nvalsPerColor = 4;
                    if (readAlpha)
                        nvalsPerColor = 5;
                    for(size_t j = 0; j < fvec.size() / nvalsPerColor; ++j)
                    {
                        // Create a control point based on the values
                        // in the float vector.
                        int index = j * nvalsPerColor;
                        ColorControlPoint cpt(fvec[index],
                                              (unsigned char)(fvec[index+1]),
                                              (unsigned char)(fvec[index+2]),
                                              (unsigned char)(fvec[index+3]),
                                              (readAlpha
                                                  ? (unsigned char)(fvec[index+4])
                                                  : 255));
                        ccpl.AddControlPoints(cpt);
                    }

                    // If the color table is already in the list, remove it.
                    // Then add the new color table to the list.
                    RemoveColorTable(nameNode->AsString());
                    AddColorTable(nameNode->AsString(), ccpl);
                }
            }
        } // end for i
    }

    if((node = searchNode->GetNode("activeContinuous")) != 0)
        SetActiveContinuous(node->AsString());

    if((node = searchNode->GetNode("activeDiscrete")) != 0)
        SetActiveDiscrete(node->AsString());

    if((node = searchNode->GetNode("groupingFlag")) != 0)
        SetGroupingFlag(node->AsBool());

    // For older version compatibility...
    if((node = searchNode->GetNode("activeColorTable")) != 0)
        SetActiveContinuous(node->AsString());
}
Exemplo n.º 20
0
// ######################################################################
Image<float> ContourBoundaryDetector::getNonMaxSuppression
(Image<float> bImg)
{
  int w = bImg.getWidth();
  int h = bImg.getHeight();
  Image<float> bImgNMS(w,h,ZEROS);

  // set up kernel for non-max suppression
  int wSize = BOUNDARY_STEP_SIZE+1;
  std::vector<std::vector<Point2D<int> > > sCoordsL(NUM_RIDGE_DIRECTIONS);
  std::vector<std::vector<Point2D<int> > > sCoordsR(NUM_RIDGE_DIRECTIONS);
  std::vector<std::vector<Point2D<int> > > cCoords (NUM_RIDGE_DIRECTIONS);


  for(uint k = 0; k < NUM_RIDGE_DIRECTIONS; k++)
    {
      cCoords [k] = std::vector<Point2D<int> >();  
      sCoordsL[k] = std::vector<Point2D<int> >();  
      sCoordsR[k] = std::vector<Point2D<int> >();  
    }

  // Non-max suppressed values for each direction
  itsRidgeDirectionNMS.clear();
  for(uint k = 0; k < NUM_RIDGE_DIRECTIONS; k++)
    itsRidgeDirectionNMS.push_back( Image<float>(w,h,ZEROS));  

  for(int i = -wSize/2; i <= wSize/2; i++)
    {
      for(int j = -wSize/2; j <= wSize/2; j++)
	{
	  if( i == 0) cCoords [0].push_back(Point2D<int>(i,j));
	  if( i <  0) sCoordsL[0].push_back(Point2D<int>(i,j));
	  if( i >  0) sCoordsR[0].push_back(Point2D<int>(i,j));

	  if(-j == i) cCoords [1].push_back(Point2D<int>(i,j));
	  if(-j >  i) sCoordsL[1].push_back(Point2D<int>(i,j));
	  if( i > -j) sCoordsR[1].push_back(Point2D<int>(i,j));	  

	  if( j == 0) cCoords [2].push_back(Point2D<int>(i,j));
	  if( j <  0) sCoordsL[2].push_back(Point2D<int>(i,j));
	  if( j >  0) sCoordsR[2].push_back(Point2D<int>(i,j));
	  
	  if( i == j) cCoords [3].push_back(Point2D<int>(i,j));
	  if( j >  i) sCoordsL[3].push_back(Point2D<int>(i,j));
	  if( i >  j) sCoordsR[3].push_back(Point2D<int>(i,j));
	}
    }

  // go through each point
  for(int i = 0; i < w; i++)
    {
      for(int j = 0; j < h; j++)
	{
	  // get the value
	  float val = bImg.getVal(i,j);
	  Point2D<int> cpt(i,j);
	  
	  for(uint k = 0; k < NUM_RIDGE_DIRECTIONS; k++)
	    {
	      float totalC = 0.0; uint ctC = 0;
	      for(uint cc = 0; cc < cCoords[k].size(); cc++)
		{
		  Point2D<int> pt = cCoords[k][cc] + cpt;  
		  if(bImg.coordsOk(pt)) 
		    {
		      totalC += bImg.getVal(pt);
		      ctC++;
		    }
		}
	      
	      float totalL = 0.0; uint ctL = 0;
	      for(uint cl = 0; cl < sCoordsL[k].size(); cl++)
		{
		  Point2D<int> pt = sCoordsL[k][cl] + cpt;  
		  if(bImg.coordsOk(pt)) 
		    {
		      totalL += bImg.getVal(pt); ctL++;
		    }
		}
	      
	      float totalR = 0.0; uint ctR = 0;
	      for(uint cr = 0; cr < sCoordsR[k].size(); cr++)
		{
		  Point2D<int> pt = sCoordsR[k][cr] + cpt;  
		  if(bImg.coordsOk(pt)) 
		    {
		      totalR += bImg.getVal(pt); ctR++;
		    }
		}
	      
	      if(totalC/ctC > totalR/ctR && totalC/ctC > totalL/ctL 
		 && val > 0.0)  
		{
		  bImgNMS.setVal(i,j, val);

		  itsRidgeDirectionNMS[k].setVal
		    (i,j, totalC/ctC*2 - totalR/ctR - totalL/ctL);
		}
	    }
	}
    }

  return bImgNMS;
}