Exemple #1
0
 T normsquare () const { return re()*re() + im()*im(); }
Exemple #2
0
 // Field Operations
 Complex operator+ (Complex const& z) const { return Complex(re()+z.re(), im()+z.im()); }
/*!
    Sets this texture to have the contents of the image stored at \a url.

    If the environment variable QT3D_MULTITHREAD is defined, network urls
    (http, etc) are downloaded in a separate download thread, otherwise they are
    downloaded asynchronously in the current thread.
*/
void QGLTexture2D::setUrl(const QUrl &url)
{
    Q_D(QGLTexture2D);
    if (d->url == url)
        return;
    d->url = url;

    if (url.isEmpty())
    {
        d->image = QImage();
    }
    else
    {
        if (url.scheme() == QLatin1String("file") || url.scheme().toLower() == QLatin1String("qrc"))
        {
            QString fileName = url.toLocalFile();

            // slight hack since there doesn't appear to be a QUrl::toResourcePath() function
            // to convert qrc:///foo into :/foo
            if (url.scheme().toLower() == QLatin1String("qrc")) {
                // strips off any qrc: prefix and any excess slashes and replaces it with :/
                QUrl tempUrl(url);
                tempUrl.setScheme("");
                fileName = QLatin1String(":")+tempUrl.toString();
            }

            if (fileName.endsWith(QLatin1String(".dds"), Qt::CaseInsensitive))
            {
                setCompressedFile(fileName);
            }
            else
            {
                QImage im(fileName);
                if (im.isNull())
                    qWarning("Could not load texture: %s", qPrintable(fileName));
                setImage(im);
            }
        }
        else
        {
             if (!d->downloadManager) {
                if (getenv(QT3D_MULTITHREAD)) {
                    //Download in a multithreaded environment
                    d->downloadManager = new QThreadedDownloadManager();
                } else {
                    //Download in a single threaded environment
                    d->downloadManager = new QDownloadManager();
                }
                connect (d->downloadManager,SIGNAL(downloadComplete(QByteArray)),this, SLOT(textureRequestFinished(QByteArray)));
            }

            //Create a temporary image that will be used until the Url is loaded.
            static QImage tempImg(128,128, QImage::Format_RGB32);
            QColor fillcolor(Qt::gray);
            tempImg.fill(fillcolor.rgba());
            setImage(tempImg);

            if (!d->downloadManager->beginDownload(QUrl(url.toString()))) {
                qWarning("Unable to issue texture download request.");
            }
        }
    }
}
Exemple #4
0
Complex<T> Complex<T>::operator* (Complex const& z) const {
   return Complex<T>(re()*z.re() - im()*z.im(), re()*z.im() + im()*z.re());
}
Exemple #5
0
// len of array = num_point_qft
double *compute_qft(double *array, int n_qft_point, int n) {
  int len_nums_complex = pow(2,n_qft_point);
  std::complex<double> *nums_complex = (std::complex<double> *)malloc(sizeof(std::complex<double>) *len_nums_complex);
  std::complex<double> im(0, 1); 
  
  
  // //

  // printf("array: %d\n",n );
  // for(int i=0;i<n_qft_point;i++)
  // {
  //   printf("%f,",array[i] );
  // }
  // printf("\n");

  std::vector < ublas::vector<std::complex<double> > > v;

  // for (int i = n_qft_point-1; i >= 0; i-=1)
  // {
  //   ublas::vector<std::complex<double> > v1(2);

  //   v1(0)=1.0;
  //   v1(1)=std::exp(2.0*im * pi * array[i]);
  //   v.push_back(v1);
  // }

  for (int i = 0; i <n_qft_point; i+=1)
  {
    ublas::vector<std::complex<double> > v1(2);

    v1(0)=1.0;
    v1(1)=std::exp(2.0*im * pi * array[i]);
    v.push_back(v1);
  }
 // printf("expstart: %d\n",n);
 //  for (int i=0; i<n_qft_point; i++) 
 //    {
 //      printf("%f,%f\n",real(v[i](0) ),imag(v[i](0) ) );
 //      printf("%f,%f\n",real(v[i](1) ),imag(v[i](1) ) );
 //    }
  // ublas::matrix<std::complex<double> > m2(v[0].size(), v[1].size());
  // m2 =  outer_prod(v[0], v[1]);

  // int linear_i=0;
  // //printf("expstart: %d\n",n);
  // for(int i = 0;i< m2.size1();i++)
  // {
  //   for(int j=0;j<m2.size2();j++)
  //   {
  //     //printf("%f,%f\n",real(m(j,i) ),imag(m(j,i) ) );
  //     nums_complex[linear_i] = m2(j,i);
  //     linear_i++;
  //   }
  // }
// for loop for tensor
    // ublas::vector<std::complex<double> > v_current = v.back() ;
    // v.pop_back();
    // ublas::vector<std::complex<double> > v_sec_current = v.back();
    // v.pop_back();

    // ublas::matrix<std::complex<double> > m = outer_prod(v_current, v_sec_current);
    // ublas::vector<std::complex<double> > v_tmp_product(v_current.size()*v_sec_current.size());


    ublas::vector<std::complex<double> > v_current=v[0];
    ublas::vector<std::complex<double> > v_sec_current=v[1];

    ublas::matrix<std::complex<double> > m =outer_prod(v_current, v_sec_current);
    ublas::vector<std::complex<double> > v_tmp_product(v_current.size()*v_sec_current.size());
   if(n_qft_point<=2)
   {


      for (int k = 1; k < n_qft_point; ++k)
      {

        // v_current = v.back();
        // v.pop_back();
        // v_sec_current = v.back();
        // v.pop_back();
         
        // m =  outer_prod(v_current, v_sec_current);
        

        int cnt=0;
        for(int i = 0;i< m.size1();i++)
        {
          for(int j=0;j<m.size2();j++)
          {

            v_tmp_product[cnt]=m(i,j);
            cnt++;
          }
        }
        v_current.resize(cnt,0);
        v_current = v_tmp_product;
        v_sec_current.resize(2,0);
        v_sec_current = v[k];
        m.resize(v_current.size(),v_sec_current.size(),0);
        m = outer_prod(v_current,v_sec_current);
        if(k!=n_qft_point-1)
        {
          v_tmp_product.resize(v_current.size()*v_sec_current.size(),0);
        }


      }
     }
     else
     {
        for (int k = 1; k < n_qft_point; ++k)
        {

          // v_current = v.back();
          // v.pop_back();
          // v_sec_current = v.back();
          // v.pop_back();
           
          // m =  outer_prod(v_current, v_sec_current);
          
          // printf("expstart: %d\n",n);
          int cnt=0;
          for(int i = 0;i< m.size1();i++)
          {
            for(int j=0;j<m.size2();j++)
            {
              // printf("%f,%f\n",real(m(j,i) ),imag(m(j,i) ) );
              v_tmp_product[cnt]=m(i,j);
              cnt++;
            }
          }
          v_current.resize(cnt,0);
          v_current = v_tmp_product;
          v_sec_current.resize(2,0);
          v_sec_current = v[k+1];
          m.resize(v_current.size(),v_sec_current.size(),0);
          m = outer_prod(v_current,v_sec_current);
          if(k!=n_qft_point-1)
          {
            v_tmp_product.resize(v_current.size()*v_sec_current.size());
          }
        }
     }


  for (int i = len_nums_complex-1; i >=0 ; i--) 
  {
   // nums_complex[i] = v_tmp_product.back();
   // v_tmp_product.pop_back();
     nums_complex[i] = normalize*v_tmp_product[i];//(double)n+(double)n*im;
  }

  // printf("%d\n",v_tmp_product.size() );


// printf("expstart: %d\n",n);
//   for (int i = 0; i <len_nums_complex; i++) 
//   {
//     //nums_complex[i] = std::exp(im * pi/4.0);//std::exp(im*pi/4.0);// exp(2*pi*array[i])+(double)n;
//     printf("%f,", real(nums_complex[i]));
//     printf("%f,", imag(nums_complex[i]));
//     printf("expend\n");
//     // printf("world_rank:  with number %f\n",nums[i] );
//   }

  






  int len_nums = 2*pow(2,n_qft_point);
  double *nums = (double *)malloc(sizeof(double) * len_nums);
  assert(nums != NULL);


  // bringing the nums_complex 1d array to 
  for (int i = 0; i < len_nums_complex; i++) {

    nums[2*i] = real(nums_complex[i]);
    nums[2*i+1]= imag(nums_complex[i]);
    //printf("world_rank: %d , %dth real number %f, img number %f\n",n,i,nums[2*i],nums[2*i+1] );
  }
  return nums;
}
Exemple #6
0
/**
 * If a contact is double-clicked send out a signal to open a chat with them.
 */
void ChatRoomControlImp::doubleClick( QListBoxItem* ){
  if ( buddyList->currentItem() == -1)
    QMessageBox::information(this, "Kinkatta - Message","Select a buddy.", QMessageBox::Ok);
  else
    emit ( im(buddyList->currentText()) );
}
Exemple #7
0
int main (int argc,char** argv) 
{
    namespace po = boost::program_options;
    
    bool verbose=false;
    std::vector<std::string> svg_files;
    
    try
    {
        po::options_description desc("svg2png utility");
        desc.add_options()
            ("help,h", "produce usage message")
            ("version,V","print version string")
            ("verbose,v","verbose output")
            ("svg",po::value<std::vector<std::string> >(),"svg file to read")
            ;
        
        po::positional_options_description p;
        p.add("svg",-1);
        po::variables_map vm;        
        po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
        po::notify(vm);

        if (vm.count("version"))
        {
            std::clog<<"version 0.3.0" << std::endl;
            return 1;
        }

        if (vm.count("help")) 
        {
            std::clog << desc << std::endl;
            return 1;
        }
        if (vm.count("verbose")) 
        {
            verbose = true;
        }

        if (vm.count("svg"))
        {
            svg_files=vm["svg"].as< std::vector<std::string> >();
        }
        else
        {
            std::clog << "please provide an svg file!" << std::endl;
            return -1;
        }

        std::vector<std::string>::const_iterator itr = svg_files.begin();
        if (itr == svg_files.end())
        {
            std::clog << "no svg files to render" << std::endl;
            return 0;
        }
        while (itr != svg_files.end())
        {

            std::string svg_name (*itr++);

            boost::optional<mapnik::marker_ptr> marker_ptr = mapnik::marker_cache::instance()->find(svg_name, false);
            if (marker_ptr) {
            
                mapnik::marker marker  = **marker_ptr;
                if (marker.is_vector()) {
    
                    typedef agg::pixfmt_rgba32_plain pixfmt;
                    typedef agg::renderer_base<pixfmt> renderer_base;
                    agg::rasterizer_scanline_aa<> ras_ptr;
                    agg::scanline_u8 sl;

                    double opacity = 1;
                    double scale_factor_ = .95;
                    int w = marker.width();
                    int h = marker.height();
                    mapnik::image_32 im(w,h);
                    agg::rendering_buffer buf(im.raw_data(), w, h, w * 4);
                    pixfmt pixf(buf);
                    renderer_base renb(pixf);

                    mapnik::box2d<double> const& bbox = (*marker.get_vector_data())->bounding_box();
                    mapnik::coord<double,2> c = bbox.center();
                    // center the svg marker on '0,0'
                    agg::trans_affine mtx = agg::trans_affine_translation(-c.x,-c.y);
                    // apply symbol transformation to get to map space
                    mtx *= agg::trans_affine_scaling(scale_factor_);
                    // render the marker at the center of the marker box
                    mtx.translate(0.5 * w, 0.5 * h);

                    mapnik::svg::vertex_stl_adapter<mapnik::svg::svg_path_storage> stl_storage((*marker.get_vector_data())->source());
                    mapnik::svg::svg_path_adapter svg_path(stl_storage);
                    mapnik::svg::svg_renderer<mapnik::svg::svg_path_adapter,
                                 agg::pod_bvector<mapnik::svg::path_attributes> > svg_renderer_this(svg_path,
                                         (*marker.get_vector_data())->attributes());

                    svg_renderer_this.render(ras_ptr, sl, renb, mtx, opacity, bbox);

                    boost::algorithm::ireplace_last(svg_name,".svg",".png");
                    mapnik::save_to_file<mapnik::image_data_32>(im.data(),svg_name,"png");
                    std::ostringstream s;
                    s << "open " << svg_name;
                    system(s.str().c_str());
                }
            }
        }
    }
    catch (...)
    {
        std::clog << "Exception of unknown type!" << std::endl;
        return -1;
    }

    return 0;
}
Exemple #8
0
int main ( )
{
  Chars errMsg;
  GHNConfig c;
  //cout << c << endl;

  ifstream in("../wp.in");
  in >> c;
  cout << c << endl;

  FreeGroup G;
  cout << "Enter a free group: ";
  errMsg = cin >> G;
  if( errMsg.length() > 0 ) {
    cout << errMsg;
    exit(0);
  }
  cout << endl;
  
  VectorOf<Chars> v = G.namesOfGenerators();
  int rLen = v.length() + 1;
  VectorOf<Chars> r(rLen);
  for( int i = 0; i < rLen - 1; ++i )
    if( v[i] != "x" && v[i] != "X" )
      r[i] = v[i];
    else
      error("x is reserved for variables\n");
  r[rLen-1] = "x";

  FreeGroup F(r);
  cout << "Enter an equation (a word) with one variable x:";
  Word w;
 
  w = F.readWord(cin,errMsg);
  if( errMsg.length() > 0 ) {
    cout << errMsg;
    exit(0);
  }
  cout << endl;

  VectorOf<Word> im(rLen);
  for( int i = 0; i < rLen; ++i )
    im[i] = Word(Generator(i+1));
  Map M(F,F,im);

  int popSize = c.populationSize();
  GAWord pop[popSize],newPop[popSize];
  for( int i = 0; i < popSize; ++i ) {
    pop[i] = GAWord(rLen-1,Word());
  }

  int fit[popSize];

  // the main loop

  int numOfGens = c.numOfGenerations();
  //bool bHaveFitnessScaling = c.haveFitnessScaling();
  float crossRate = c.chanceOfCrossover();
  float mutRate = c.chanceOfMutation();
  UniformRandom devgen;
  int max, min, minInd, g;
 
  // create the original random populations
  for( int i = 0; i < popSize; ++i ) {
    pop[i] = pop[i].randomWord();
  }
  
  for( g = 0; g < numOfGens; ++g ) {
    
    min = MAXINT; max = 0;  minInd = -1;
    
    // compute fitness values
    for( int i = 0; i < popSize; ++i ) {
	
      M.setGeneratingImages(rLen-1,(pop[i]).getWord());
      fit[i] = M.imageOf(w).freelyReduce().length();

      if( fit[i] < min ) {
	min = fit[i];
	minInd = i;
      }
      else if( fit[i] > max )
	max = fit[i];
    }
    
    // print current results
    cout << "Generation: " << g << "   Fitness: " << min << endl;
    /*
    if( g % 100 == 0 ) {
      for( int i = 0; i < popSize; ++i ) {
	cout << "x" << i << " = ";
	F.printWord(cout, (pop[i]).getWord());
	cout << endl;
      }
      cout << endl;
    }
    */
    // exit if found a solution
    if( min == 0 ) {
      cout << "x = ";
      F.printWord(cout, (pop[minInd]).getWord());
      cout << endl;
      return 0;
    }
    
    // make fitness values suitable for Roulette wheel selection
    int base = max + 1;
    for( int i = 0; i < popSize; ++i )
      fit[i] = base - fit[i];
    
    // fitness scaling
    if( c.haveFitnessScaling() )
      for( int i = 0; i < popSize; ++i )
	fit[i] = fit[i] * fit[i];
    
    // crossover
    RouletteWheel<int> wheel(popSize,fit);
    for( int i = 0; i < popSize; ++i ) {
      if( devgen.rand() <= crossRate ) {
	int i1 = wheel.GetIndex();
	int i2 = wheel.GetIndex();
	newPop[i] = pop[i1].crossover(pop[i2]);
      }
      else {
	newPop[i] = pop[i];
      }
    }
    
    
    // mutation
    for( int i = 0; i < popSize; ++i ) {
      if( devgen.rand() <= mutRate ) {
	newPop[i] = newPop[i].mutate();
      }
    }
    
    
    // elitist selection
    if( c.haveElitistSelection() ) {
      newPop[0] = pop[minInd];
    }
    
    // prepare for the next iteration
    for( int i = 0; i < popSize; ++i ) {
      pop[i] = newPop[i];
    }    
  }
}
Exemple #9
0
/*
 * Add an attribute to the hash calculation.
 * **IMPORTANT: any new hard coded support for a data type in here
 * must be added to isGreenplumDbHashable() below!
 *
 * Note that the caller should provide the base type if the datum is
 * of a domain type. It is quite expensive to call get_typtype() and
 * getBaseType() here since this function gets called a lot for the
 * same set of Datums.
 *
 * @param hashFn called to update the hash value.
 * @param clientData passed to hashFn.
 */
void
hashDatum(Datum datum, Oid type, datumHashFunction hashFn, void *clientData)
{
	void	   *buf = NULL;		/* pointer to the data */
	size_t		len = 0;		/* length for the data buffer */
	
	int64		intbuf;			/* an 8 byte buffer for all integer sizes */
		
	float4		buf_f4;
	float8		buf_f8;
	Timestamp	tsbuf;			/* timestamp data dype is either a double or
								 * int8 (determined in compile time) */
	TimestampTz tstzbuf;
	DateADT		datebuf;
	TimeADT		timebuf;
	TimeTzADT  *timetzptr;
	Interval   *intervalptr;
	AbsoluteTime abstime_buf;
	RelativeTime reltime_buf;
	TimeInterval tinterval;
	AbsoluteTime tinterval_len;
	
	Numeric		num;
	bool		bool_buf;
	char        char_buf;
	Name		namebuf;
	
	ArrayType  *arrbuf;
	inet		 *inetptr; /* inet/cidr */
	unsigned char inet_hkey[sizeof(inet_struct)];
	macaddr		*macptr; /* MAC address */
	
	VarBit		*vbitptr;
	
	oidvector  *oidvec_buf;
	Complex		*complex_ptr;
	Complex		complex_buf;
	double		complex_real;
	double		complex_imag;
	
	Cash		cash_buf;
	pg_uuid_t  *uuid_buf;

	/*
	 * special case buffers
	 */
	uint32		nanbuf;
	uint32		invalidbuf;

	void *tofree = NULL;

	/*
	 * Select the hash to be performed according to the field type we are adding to the
	 * hash.
	 */
	switch (type)
	{
		/*
		 * ======= NUMERIC TYPES ========
		 */
		case INT2OID:			/* -32 thousand to 32 thousand, 2-byte storage */
			intbuf = (int64) DatumGetInt16(datum);		/* cast to 8 byte before
														 * hashing */
			buf = &intbuf;
			len = sizeof(intbuf);
			break;

		case INT4OID:			/* -2 billion to 2 billion integer, 4-byte
								 * storage */
			intbuf = (int64) DatumGetInt32(datum);		/* cast to 8 byte before
														 * hashing */
			buf = &intbuf;
			len = sizeof(intbuf);
			break;
			
		case INT8OID:			/* ~18 digit integer, 8-byte storage */
			intbuf = DatumGetInt64(datum);		/* cast to 8 byte before
												 * hashing */
			buf = &intbuf;
			len = sizeof(intbuf);
			break;

		case FLOAT4OID: /* single-precision floating point number,
								 * 4-byte storage */
			buf_f4 = DatumGetFloat4(datum);

			/*
			 * On IEEE-float machines, minus zero and zero have different bit
			 * patterns but should compare as equal.  We must ensure that they
			 * have the same hash value, which is most easily done this way:
			 */
			if (buf_f4 == (float4) 0)
				buf_f4 = 0.0;

			buf = &buf_f4;
			len = sizeof(buf_f4);
			break;

		case FLOAT8OID: /* double-precision floating point number,
								 * 8-byte storage */
			buf_f8 = DatumGetFloat8(datum);

			/*
			 * On IEEE-float machines, minus zero and zero have different bit
			 * patterns but should compare as equal.  We must ensure that they
			 * have the same hash value, which is most easily done this way:
			 */
			if (buf_f8 == (float8) 0)
				buf_f8 = 0.0;

			buf = &buf_f8;
			len = sizeof(buf_f8);
			break;

		case NUMERICOID:

			num = DatumGetNumeric(datum);

			if (NUMERIC_IS_NAN(num))
			{
				nanbuf = NAN_VAL;
				buf = &nanbuf;
				len = sizeof(nanbuf);
			}
			else
				/* not a nan */
			{
				buf = num->n_data;
				len = (VARSIZE(num) - NUMERIC_HDRSZ);
			}

            /* 
             * If we did a pg_detoast_datum, we need to remember to pfree, 
             * or we will leak memory.  Because of the 1-byte varlena header stuff.
             */
            if (num != DatumGetPointer(datum)) 
                tofree = num;

			break;
		
		/*
		 * ====== CHARACTER TYPES =======
		 */
		case CHAROID:			/* char(1), single character */
			char_buf = DatumGetChar(datum);
			buf = &char_buf;
			len = 1;
			break;

		case BPCHAROID: /* char(n), blank-padded string, fixed storage */
		case TEXTOID:   /* text */
		case VARCHAROID: /* varchar */ 
		case BYTEAOID:   /* bytea */
			{
				int tmplen;
				varattrib_untoast_ptr_len(datum, (char **) &buf, &tmplen, &tofree);
				/* adjust length to not include trailing blanks */
				if (type != BYTEAOID && tmplen > 1)
					tmplen = ignoreblanks((char *) buf, tmplen);

				len = tmplen;
				break;
			}

		case NAMEOID:
			namebuf = DatumGetName(datum);
			len = NAMEDATALEN;
			buf = NameStr(*namebuf);

			/* adjust length to not include trailing blanks */
			if (len > 1)
				len = ignoreblanks((char *) buf, len);
			break;
		
		/*
		 * ====== OBJECT IDENTIFIER TYPES ======
		 */
		case OIDOID:				/* object identifier(oid), maximum 4 billion */
		case REGPROCOID:			/* function name */
		case REGPROCEDUREOID:		/* function name with argument types */
		case REGOPEROID:			/* operator name */
		case REGOPERATOROID:		/* operator with argument types */
		case REGCLASSOID:			/* relation name */
		case REGTYPEOID:			/* data type name */
			intbuf = (int64) DatumGetUInt32(datum);	/* cast to 8 byte before hashing */
			buf = &intbuf;
			len = sizeof(intbuf);
			break;

        case TIDOID:                /* tuple id (6 bytes) */
            buf = DatumGetPointer(datum);
            len = SizeOfIptrData;
            break;
			
		/*
		 * ====== DATE/TIME TYPES ======
		 */
		case TIMESTAMPOID:		/* date and time */
			tsbuf = DatumGetTimestamp(datum);
			buf = &tsbuf;
			len = sizeof(tsbuf);
			break;

		case TIMESTAMPTZOID:	/* date and time with time zone */
			tstzbuf = DatumGetTimestampTz(datum);
			buf = &tstzbuf;
			len = sizeof(tstzbuf);
			break;

		case DATEOID:			/* ANSI SQL date */
			datebuf = DatumGetDateADT(datum);
			buf = &datebuf;
			len = sizeof(datebuf);
			break;

		case TIMEOID:			/* hh:mm:ss, ANSI SQL time */
			timebuf = DatumGetTimeADT(datum);
			buf = &timebuf;
			len = sizeof(timebuf);
			break;

		case TIMETZOID: /* time with time zone */
			
			/*
			 * will not compare to TIMEOID on equal values.
			 * Postgres never attempts to compare the two as well.
			 */
			timetzptr = DatumGetTimeTzADTP(datum);
			buf = (unsigned char *) timetzptr;
			
			/*
			 * Specify hash length as sizeof(double) + sizeof(int4), not as
			 * sizeof(TimeTzADT), so that any garbage pad bytes in the structure
			 * won't be included in the hash!
			 */
			len = sizeof(timetzptr->time) + sizeof(timetzptr->zone);
			break;

		case INTERVALOID:		/* @ <number> <units>, time interval */
			intervalptr = DatumGetIntervalP(datum);
			buf = (unsigned char *) intervalptr;
			/*
			 * Specify hash length as sizeof(double) + sizeof(int4), not as
			 * sizeof(Interval), so that any garbage pad bytes in the structure
			 * won't be included in the hash!
			 */
			len = sizeof(intervalptr->time) + sizeof(intervalptr->month);
			break;
			
		case ABSTIMEOID:
			abstime_buf = DatumGetAbsoluteTime(datum);
			
			if (abstime_buf == INVALID_ABSTIME)
			{
				/* hash to a constant value */
				invalidbuf = INVALID_VAL;
				len = sizeof(invalidbuf);
				buf = &invalidbuf;
			}
			else
			{
				len = sizeof(abstime_buf);
				buf = &abstime_buf;
			}
					
			break;

		case RELTIMEOID:
			reltime_buf = DatumGetRelativeTime(datum);
			
			if (reltime_buf == INVALID_RELTIME)
			{
				/* hash to a constant value */
				invalidbuf = INVALID_VAL;
				len = sizeof(invalidbuf);
				buf = &invalidbuf;
			}
			else
			{
				len = sizeof(reltime_buf);
				buf = &reltime_buf;
			}
				
			break;
			
		case TINTERVALOID:
			tinterval = DatumGetTimeInterval(datum);
			
			/*
			 * check if a valid interval. the '0' status code
			 * stands for T_INTERVAL_INVAL which is defined in
			 * nabstime.c. We use the actual value instead
			 * of defining it again here.
			 */
			if(tinterval->status == 0 ||
			   tinterval->data[0] == INVALID_ABSTIME ||
			   tinterval->data[1] == INVALID_ABSTIME)
			{
				/* hash to a constant value */
				invalidbuf = INVALID_VAL;
				len = sizeof(invalidbuf);
				buf = &invalidbuf;				
			}
			else
			{
				/* normalize on length of the time interval */
				tinterval_len = tinterval->data[1] -  tinterval->data[0];
				len = sizeof(tinterval_len);
				buf = &tinterval_len;	
			}

			break;
			
		/*
		 * ======= NETWORK TYPES ========
		 */
		case INETOID:
		case CIDROID:
			
			inetptr = DatumGetInetP(datum);
			len = inet_getkey(inetptr, inet_hkey, sizeof(inet_hkey)); /* fill-in inet_key & get len */
			buf = inet_hkey;
			break;
		
		case MACADDROID:
			
			macptr = DatumGetMacaddrP(datum);
			len = sizeof(macaddr);
			buf = (unsigned char *) macptr;
			break;
			
		/*
		 * ======== BIT STRINGS ========
		 */
		case BITOID:
		case VARBITOID:
			
			/*
			 * Note that these are essentially strings.
			 * we don't need to worry about '10' and '010'
			 * to compare, b/c they will not, by design.
			 * (see SQL standard, and varbit.c)
			 */
			vbitptr = DatumGetVarBitP(datum);
			len = VARBITBYTES(vbitptr);
			buf = (char *) VARBITS(vbitptr);
			break;

		/*
		 * ======= other types =======
		 */
		case BOOLOID:			/* boolean, 'true'/'false' */
			bool_buf = DatumGetBool(datum);
			buf = &bool_buf;
			len = sizeof(bool_buf);
			break;
			
		/*
		 * ANYARRAY is a pseudo-type. We use it to include
		 * any of the array types (OIDs 1007-1033 in pg_type.h).
		 * caller needs to be sure the type is ANYARRAYOID
		 * before calling cdbhash on an array (INSERT and COPY do so).
		 */
		case ANYARRAYOID:	
					
			arrbuf = DatumGetArrayTypeP(datum);
			len = VARSIZE(arrbuf) - VARHDRSZ;
			buf = VARDATA(arrbuf);
			break;
			
		case OIDVECTOROID:	
			oidvec_buf = (oidvector *) DatumGetPointer(datum);
			len = oidvec_buf->dim1 * sizeof(Oid);
			buf = oidvec_buf->values;
			break;
			
		case CASHOID: /* cash is stored in int64 internally */
			cash_buf = (* (Cash *)DatumGetPointer(datum));
			len = sizeof(Cash);
			buf = &cash_buf;
			break;

		/* pg_uuid_t is defined as a char array of size UUID_LEN in uuid.c */
		case UUIDOID:
			uuid_buf = DatumGetUUIDP(datum);
			len = UUID_LEN;
			buf = (char *)uuid_buf;
			break;
				
		case COMPLEXOID:		
			complex_ptr  = DatumGetComplexP(datum);
			complex_real = re(complex_ptr);
			complex_imag = im(complex_ptr);
			/*
			* On IEEE-float machines, minus zero and zero have different bit
			* patterns but should compare as equal.  We must ensure that they
			* have the same hash value, which is most easily done this way:
			*/
			if (complex_real == (float8) 0)
			{
				complex_real = 0.0;
			}
			if (complex_imag == (float8) 0)
			{
				complex_imag = 0.0;
			}
				
			INIT_COMPLEX(&complex_buf, complex_real, complex_imag);
			len = sizeof(Complex);
			buf = (unsigned char *) &complex_buf;
			break;

		default:
			ereport(ERROR,
					(errcode(ERRCODE_CDB_FEATURE_NOT_YET),
					 errmsg("Type %u is not hashable.", type)));

	}							/* switch(type) */

	/* do the hash using the selected algorithm */
	hashFn(clientData, buf, len);
	if (tofree)
		pfree(tofree);
}
void InputOutputMap_Test::pluginNames()
{
    InputOutputMap im(m_doc, 4);
    QCOMPARE(im.outputPluginNames().size(), 1);
    QCOMPARE(im.outputPluginNames().at(0), QString("I/O Plugin Stub"));
}
void InputOutputMap_Test::setInputPatch()
{
    InputOutputMap im(m_doc, 4);

    IOPluginStub* stub = static_cast<IOPluginStub*>
                                (m_doc->ioPluginCache()->plugins().at(0));
    QVERIFY(stub != NULL);

    QLCInputProfile* prof = new QLCInputProfile();
    prof->setManufacturer("Foo");
    prof->setModel("Bar");
    im.addProfile(prof);

    QVERIFY(im.inputPatch(0) == NULL);
    QVERIFY(im.inputPatch(1) == NULL);
    QVERIFY(im.inputPatch(2) == NULL);
    QVERIFY(im.inputPatch(3) == NULL);
    QVERIFY(im.inputMapping(stub->name(), 0) == InputOutputMap::invalidUniverse());
    QVERIFY(im.inputMapping(stub->name(), 1) == InputOutputMap::invalidUniverse());
    QVERIFY(im.inputMapping(stub->name(), 2) == InputOutputMap::invalidUniverse());
    QVERIFY(im.inputMapping(stub->name(), 3) == InputOutputMap::invalidUniverse());

    QVERIFY(im.setInputPatch(0, "Foobar", 0, prof->name()) == true);
    QVERIFY(im.inputPatch(0) == NULL);
    QVERIFY(im.inputMapping(stub->name(), 0) == InputOutputMap::invalidUniverse());

    QVERIFY(im.inputPatch(1) == NULL);
    QVERIFY(im.inputMapping(stub->name(), 1) == InputOutputMap::invalidUniverse());

    QVERIFY(im.inputPatch(2) == NULL);
    QVERIFY(im.inputMapping(stub->name(), 2) == InputOutputMap::invalidUniverse());

    QVERIFY(im.inputPatch(3) == NULL);
    QVERIFY(im.inputMapping(stub->name(), 3) == InputOutputMap::invalidUniverse());

    QVERIFY(im.setInputPatch(0, stub->name(), 0) == true);
    QVERIFY(im.inputPatch(0)->plugin() == stub);
    QVERIFY(im.inputPatch(0)->input() == 0);
    QVERIFY(im.inputPatch(0)->profile() == NULL);
    QVERIFY(im.inputMapping(stub->name(), 0) == 0);

    QVERIFY(im.inputPatch(1) == NULL);
    QVERIFY(im.inputMapping(stub->name(), 1) == InputOutputMap::invalidUniverse());

    QVERIFY(im.inputPatch(2) == NULL);
    QVERIFY(im.inputMapping(stub->name(), 2) == InputOutputMap::invalidUniverse());

    QVERIFY(im.inputPatch(3) == NULL);
    QVERIFY(im.inputMapping(stub->name(), 3) == InputOutputMap::invalidUniverse());

    QVERIFY(im.setInputPatch(2, stub->name(), 3, prof->name()) == true);
    QVERIFY(im.inputPatch(0)->plugin() == stub);
    QVERIFY(im.inputPatch(0)->input() == 0);
    QVERIFY(im.inputPatch(0)->profile() == NULL);
    QVERIFY(im.inputMapping(stub->name(), 0) == 0);

    QVERIFY(im.inputPatch(1) == NULL);
    QVERIFY(im.inputMapping(stub->name(), 1) == InputOutputMap::invalidUniverse());

    QVERIFY(im.inputPatch(2)->plugin() == stub);
    QVERIFY(im.inputPatch(2)->input() == 3);
    QVERIFY(im.inputPatch(2)->profile() == prof);
    QVERIFY(im.inputMapping(stub->name(), 2) == InputOutputMap::invalidUniverse());

    QVERIFY(im.inputPatch(3) == NULL);
    QVERIFY(im.inputMapping(stub->name(), 3) == 2);

    // Universe out of bounds
    QVERIFY(im.setInputPatch(im.universes(), stub->name(), 0) == false);
}
Exemple #12
0
void CChirpZ::ConvertFloat(long double MathPiWithSign) {
    
    // assume input data have been stored in X from 0 to mPoints-1.
    // pad the rest with zeros
    memset(X + (mPoints * Cx2Re), 0, sizeof(float) * Cx2Re * (mPointsChirpZ - mPoints));
    
    // generate C[n]
    // use range reduction due to cexp realizations
    // cexp is realized with VECTORMATH=0, so sin()/cos()/exp() are used.
    long long int n  = 0;
    long long int n2 = 0;
    long long int mPoints2 = 2 * mPoints;
    long double Index = 0.0L;
    
    for(int i = 0; i < mPoints; i++) {
        //n2 = (long long int)i;
        //n2 = n2 * n2;
        
        n2 = n % mPoints2;
        Index = (long double)n2 / (long double)mPoints * MathPiWithSign;
        n += (2*i+1);
        C[re(i)] = 0.0f;
        C[im(i)] = (float)Index;
    }
    
    Complex8f ax;
    Complex8f bx;
    Complex8f cx;
    Complex8f dx;
    for(int i = 0; i < mPoints*Cx2Re; i+=8) {
        cx.load(X+i);
        ax.load(C+i);
        bx = cexp(-ax);  // for modulation of X
        dx = bx * cx;
        dx.store(X+i);
        
        bx = cexp(ax);   // for de-modulation of Y and convolution
        bx.store(C+i);
    }
    
    // so far X has been modulated and zero padded
    // coefficients for de-modulation of Y is ready
    // start to generate h[n] for convolution based on its even symmetry.
    for(int i = 1; i < mPoints; i++) {
        C[re(mPointsChirpZ-i)] = C[re(i)];
        C[im(mPointsChirpZ-i)] = C[im(i)];        
    }

    std::unique_ptr<CFastFourier> pFFTL(new CFastFourier);
    pFFTL->fft_f(mPointsChirpZ, X, Xs);
    pFFTL->fft_f(mPointsChirpZ, C, Cs);

    for(int i = 0; i < mPointsChirpZ*Cx2Re; i+=8) {
        ax.load(Xs+i);
        bx.load(Cs+i);
        cx = ax * bx;
        cx.store(Xs+i);
    }  
    
    pFFTL->ifft_f(mPointsChirpZ, Xs, X);
    
    Complex8f GainIFFTx((float)mPointsChirpZ);
    for(int i = 0; i < mPoints*Cx2Re; i+=8) {
        ax.load(X+i);
        bx.load(C+i);
        cx = ax / bx;
        dx = cx / GainIFFTx;
        dx.store(X+i);
    }    
}
Exemple #13
0
void print::prepareDocument_All_Thermal(){
    mDoc2Print = new QTextDocument();
    mDocCursor = QTextCursor(mDoc2Print);
    QString s;

    QTextCharFormat form;
    form.setFont(QFont( "Serif Sans Mono", 9 ));
    QTextCharFormat defaultFormat=mDocCursor.charFormat();

    s=QString("\nAdithya Medical Systems\n");


    mDocCursor.insertText(s);


    mDocCursor.setCharFormat(form);
    s=QString("\nDoctor:")+QString(currentDoctor->cDocName)+"\n";
    mDocCursor.insertText(s);

    s=QString("\nPatient:")+QString(currentPatient->cPatName)+"\n";
    mDocCursor.insertText(s);

    s=QString("\nPatient ID:")+QString(currentPatient->cId)+"\n";
    mDocCursor.insertText(s);

    s=QString("\nEye:")+eye+"\n";
    mDocCursor.insertText(s);

    s=QString("\nDate:")+QDate::currentDate().toString()+"\n";
    mDocCursor.insertText(s);

    s=QString("\nTime:")+QTime::currentTime().toString()+"\n";

    mDocCursor.insertText(s);
    QImage im("scan.png");
    QTransform rotating;
    rotating.rotate(90);
    im = im.transformed(rotating);
    im.invertPixels();
    mDocCursor.insertImage(im);

//    mDocCursor.insertText(emptyLine);
    mDocCursor.setCharFormat(defaultFormat);
    s=QString("\nAL:")+QString::number(printLocalreadings[*nCurrentReadingNumber].dAl,'f',2)+QString("\n");
    mDocCursor.insertText(s);

    s=QString("\nLT:")+QString::number(printLocalreadings[*nCurrentReadingNumber].dLt,'f',2)+QString("\n");
    mDocCursor.insertText(s);

    s=QString("\nVIT:")+QString::number(printLocalreadings[*nCurrentReadingNumber].dVit,'f',2)+QString("\n");
    mDocCursor.insertText(s);

    s=QString("ACD:")+QString::number(printLocalreadings[*nCurrentReadingNumber].dAcd,'f',2)+QString("\n");
    mDocCursor.insertText(s);

    s=QString("\nAVG AL:")+QString::number(printLocalreadings[*nCurrentReadingNumber].dAv_al,'f',2)+QString("\n");
    mDocCursor.insertText(s);

    s=QString("\nDeviation:")+QString::number(printLocalreadings[*nCurrentReadingNumber].dDeviation,'f',2)+QString("\n");
    mDocCursor.insertText(s);

    ifstream sd_calc;
    sd_calc.open("sd.dat");
    double sd;
    sd_calc.read((char*)&sd,sizeof(sd));
    s=QString("\nStd_Deviation:")+QString::number(sd)+QString("\n");
    mDocCursor.insertText(s);


    if(eye==QString("Right")){
        s=QString("\n\nK1=")+QString(currentPatient->cRk1)+QString("\nK2=")+QString(currentPatient->cRk2)+QString("\n");

    }
    else
    {
        s=QString("\nK1=")+QString(currentPatient->cLk1)+QString("\nK2=")+QString(currentPatient->cLk2)+QString("\n");
    }
    s+=QString("\nK=")+QString::number(first[0].K,'f',2)+QString("\n\nAL=")+QString::number(first[0].AL,'f',2)+QString("\t Rx=")+QString::number(first[0].Rx,'f',2);

    mDocCursor.insertText (s.toStdString().c_str());

    mDocCursor.insertText("\n\n");

    lens1.truncate(6);
    lens2.truncate(6);
    lens3.truncate(6);

    mDocCursor.setCharFormat(defaultFormat);
    if(first[0].ftype==0)
    {
        mDocCursor.insertText("\nFORMULA: SRKT\n");


        s =lens1+"     "+lens2+"     "+lens3+"\n";
        mDocCursor.insertText (s.toStdString().c_str());

        s=QString::number(first[0].AConst,'f',2)+"   "+QString::number(first[1].AConst,'f',2)+"     "+QString::number(first[2].AConst,'f',2)+"\n";

        mDocCursor.insertText(s);

    }
    else if(first[0].ftype==1)
    {
        mDocCursor.insertText("\nFORMULA: SRKII\n");

        s =lens1+"     "+lens2+"     "+lens3+"\n";
        mDocCursor.insertText (s.toStdString().c_str());

        s=QString::number(first[0].AConst,'f',2)+"   "+QString::number(first[1].AConst,'f',2)+"     "+QString::number(first[2].AConst,'f',2)+"\n";

        mDocCursor.insertText(s);

    }
    else if(first[0].ftype==2)
    {
        mDocCursor.insertText ("\nFORMULA: HOFFERQ");

        s =lens1+"     "+lens2+"     "+lens3+"\n";
        mDocCursor.insertText (s.toStdString().c_str());
        s="";
        ifstream l;
        l.open("lens.dat",ios::binary);
        lens lensVariable;
        while(l.read((char*)&lensVariable,sizeof(lensVariable))){
            qDebug()<<lensVariable.cIol;
            if(strcmp(lensVariable.cIol,lens1_2.toStdString().c_str())==0)
            {
                s="  "+QString(lensVariable.cSf);
                break;
            }
        }
        l.close();

        l.open("lens.dat",ios::binary);
        while(l.read((char*)&lensVariable,sizeof(lensVariable))){
            if(strcmp(lensVariable.cIol,lens2_2.toStdString().c_str())==0)
            {
                s+="       "+QString(lensVariable.cSf);
                break;
            }
        }
        l.close();
        l.open("lens.dat",ios::binary);
        while(l.read((char*)&lensVariable,sizeof(lensVariable))){
            if(strcmp(lensVariable.cIol,lens3_2.toStdString().c_str())==0)
            {
                s+="          "+QString(lensVariable.cSf);
                break;
            }
        }
        l.close();
        s+="\n";

        mDocCursor.insertText(s);

    }
    else if(first[0].ftype==3)
    {
        mDocCursor.insertText ("\nFORMULA: HOLLADAY\n");

        s =lens1+"     "+lens2+"     "+lens3+"\n";

        mDocCursor.insertText (s.toStdString().c_str());
        s="";
        ifstream l;
        l.open("lens.dat",ios::binary);
        lens lensVariable;
        while(l.read((char*)&lensVariable,sizeof(lensVariable))){
           qDebug()<<lensVariable.cIol;
            if(strcmp(lensVariable.cIol,lens1_2.toStdString().c_str())==0)
            {
                s="  "+QString(lensVariable.cSf);
                break;
            }
        }
        l.close();

        l.open("lens.dat",ios::binary);
        while(l.read((char*)&lensVariable,sizeof(lensVariable))){
            if(strcmp(lensVariable.cIol,lens2_2.toStdString().c_str())==0)
            {
                s+="       "+QString(lensVariable.cSf);
                break;
            }
        }
        l.close();
        l.open("lens.dat",ios::binary);
        while(l.read((char*)&lensVariable,sizeof(lensVariable))){
            if(strcmp(lensVariable.cIol,lens3_2.toStdString().c_str())==0)
            {
                s+="          "+QString(lensVariable.cSf);
                break;
            }
        }
        l.close();
        s+="\n";

        mDocCursor.insertText(s);
    }
    else if(first[0].ftype=4)
    {
       mDocCursor.insertText ("\nFORMULA: HAIGIS\n");


       s =lens1+"     "+lens2+"     "+lens3+"\n";

       mDocCursor.insertText (s.toStdString().c_str());
       s="";
       ifstream l;
       l.open("lens.dat",ios::binary);
       lens lensVariable;
       while(l.read((char*)&lensVariable,sizeof(lensVariable))){
           qDebug()<<lensVariable.cIol;
           if(strcmp(lensVariable.cIol,lens1_2.toStdString().c_str())==0)
           {
               s="  "+QString(lensVariable.cA0);
               break;
           }
       }
       l.close();

       l.open("lens.dat",ios::binary);
       while(l.read((char*)&lensVariable,sizeof(lensVariable))){
           if(strcmp(lensVariable.cIol,lens2_2.toStdString().c_str())==0)
           {
               s+="       "+QString(lensVariable.cA0);
               break;
           }
       }
       l.close();
       l.open("lens.dat",ios::binary);
       while(l.read((char*)&lensVariable,sizeof(lensVariable))){
           if(strcmp(lensVariable.cIol,lens3_2.toStdString().c_str())==0)
           {
               s+="          "+QString(lensVariable.cA0);
               break;
           }
       }
       l.close();
       s+="\n";

       mDocCursor.insertText(s);
    }
    else if(first[0].ftype==5)
    {
        mDocCursor.insertText ("\nFORMULA: BINKHORST\n");
        s =lens1+"     "+lens2+"     "+lens3+"\n";

        mDocCursor.insertText (s.toStdString().c_str());

        s=QString::number(first[0].AConst,'f',2)+"   "+QString::number(first[1].AConst,'f',2)+"     "+QString::number(first[2].AConst,'f',2)+"\n";

        mDocCursor.insertText(s);
    }

    mDocCursor.insertText ("IOL    Ref    IOL    Ref    IOL    Ref\n");
//    mDoc2Print->set
    mDocCursor.setCharFormat(form);

    for (int i=0;i<5;i++){
    if (second[0].PORx[i] < 0.0){
       s=QString::number(second[0].IOLPower[i],'f',1)+" "+QString::number(second[0].PORx[i],'f',2)+"   "+QString::number(second[1].IOLPower[i],'f',1)+" "+QString::number(second[1].PORx[i],'f',2)+"   "+QString::number(second[2].IOLPower[i],'f',1)+" "+QString::number(second[2].PORx[i],'f',2)+"\n\n";

    }
    else{
       s=QString::number(second[0].IOLPower[i],'f',1)+"  "+QString::number(second[0].PORx[i],'f',2)+"   "+QString::number(second[1].IOLPower[i],'f',1)+"  "+QString::number(second[1].PORx[i],'f',2)+"   "+QString::number(second[2].IOLPower[i],'f',1)+"  "+QString::number(second[2].PORx[i],'f',2)+"\n\n";

    }
    //qDebug()<<s;
    mDocCursor.insertText (s.toStdString().c_str());           // send 7 character greeting
   }
    mDocCursor.insertText("\n");
    mDocCursor.setCharFormat(defaultFormat);
    s="\nPEMMETROPIA\n";

    mDocCursor.insertText(s.toStdString().c_str());

    s="  "+QString::number(second[0].PEMM,'f',2)+"           "+QString::number(second[1].PEMM,'f',2)+"            "+QString::number(second[2].PEMM,'f',2)+"       ";

    mDocCursor.insertText(s);           // send 7 character greeting
    // send 7 character greeting

    mDocCursor.insertText("\n\n\n\n\n");
//    qDebug()<<"printing end";

//    QFile outfile;
//    outfile.setFileName("pout.txt");
//    outfile.open(QIODevice::Append);
//    QTextDocumentWriter t;
//    outfile.write(mDoc2Print->toPlainText().toStdString().c_str(),sizeof(mDoc2Print->toPlainText().toStdString().c_str()));

//    QProcess process;
//    process.start("lpr pout.txt");
//    process.waitForFinished(-1);

}