Esempio n. 1
0
 inline basic_message<Tag> &
 operator<< (basic_message<Tag> & msg_, 
         impl::transform_impl<Algorithm, Selector> 
             const & transformer) {
     transformer(msg_);
     return msg_;
 }
Esempio n. 2
0
    static inline bool apply(Multi const& multi,
                             Point& centroid,
                             Strategy const& strategy)
    {
#if ! defined(BOOST_GEOMETRY_CENTROID_NO_THROW)
        // If there is nothing in any of the ranges, it is not possible
        // to calculate the centroid
        if (geometry::is_empty(multi))
        {
            throw centroid_exception();
        }
#endif

        // prepare translation transformer
        translating_transformer<Multi> transformer(multi);

        typename Strategy::state_type state;

        for (typename boost::range_iterator<Multi const>::type
                it = boost::begin(multi);
            it != boost::end(multi);
            ++it)
        {
            Policy::apply(*it, transformer, strategy, state);
        }

        if ( strategy.result(state, centroid) )
        {
            // translate the result back
            transformer.apply_reverse(centroid);
            return true;
        }
        
        return false;
    }
Esempio n. 3
0
bool QgsProperty::loadVariant( const QVariant &property )
{
  QVariantMap propertyMap = property.toMap();

  d.detach();
  d->active = propertyMap.value( QStringLiteral( "active" ) ).toBool();
  d->type = static_cast< Type >( propertyMap.value( QStringLiteral( "type" ), InvalidProperty ).toInt() );

  switch ( d->type )
  {
    case StaticProperty:
      d->staticValue = propertyMap.value( QStringLiteral( "val" ) );
      // d->staticValue.convert( QVariant::nameToType( propertyElem.attribute( "valType", "QString" ).toLocal8Bit().constData() ) );
      break;

    case FieldBasedProperty:
      d->fieldName = propertyMap.value( QStringLiteral( "field" ) ).toString();
      if ( d->fieldName.isEmpty() )
        d->active = false;
      break;

    case ExpressionBasedProperty:
      d->expressionString = propertyMap.value( QStringLiteral( "expression" ) ).toString();
      if ( d->expressionString.isEmpty() )
        d->active = false;

      d->expression = QgsExpression( d->expressionString );
      d->expressionPrepared = false;
      d->expressionReferencedCols.clear();
      break;

    case InvalidProperty:
      break;

  }

  //restore transformer if present
  if ( d->transformer )
    delete d->transformer;
  d->transformer = nullptr;


  QVariant transform = propertyMap.value( QStringLiteral( "transformer" ) );

  if ( transform.isValid() )
  {
    QVariantMap transformerMap = transform.toMap();

    QgsPropertyTransformer::Type type = static_cast< QgsPropertyTransformer::Type >( transformerMap.value( QStringLiteral( "t" ), QgsPropertyTransformer::GenericNumericTransformer ).toInt() );
    std::unique_ptr< QgsPropertyTransformer > transformer( QgsPropertyTransformer::create( type ) );

    if ( transformer )
    {
      if ( transformer->loadVariant( transformerMap.value( QStringLiteral( "d" ) ) ) )
        d->transformer = transformer.release();
    }
  }

  return true;
}
Esempio n. 4
0
// for scaling text
void MacPrinterCanvas::flush()
{
	// ---- check if there is anything to do ----
	//int nchars = (int) (text_ptr_ - text_buff_);
	//if ((nchars == 0) || (lg_font_ == nil))
	//	return;
		
	// ---- render the text ----
	if (text_item_.count > 0) {
		//set font
		FontRep* fr = lg_font_->rep(nil);
		TextFont(fr->font_);
		TextFace(fr->face_);
		float a00, a01, a10, a11, a20, a21;
		transformer().matrix(a00, a01, a10, a11, a20, a21);
		int size = int(double(fr->size_)*sqrt(a00*a00 + a01*a01) +.01);
		TextSize(size);
		TextMode(fr->mode_);
//if (printing) debugfile("flush %d %d\n",toPixelX(text_item_.x), toPixelY(text_item_.y)); 		
        MoveTo(toPixelX(text_item_.x), toPixelY(text_item_.y));
        DrawText(text_item_.buffer, 0, text_item_.count);
// text_item_.buffer[text_item_.count] = '\0';
// debugfile("|%s|\n", text_item_.buffer);
    }
    text_item_.count = 0;	
	
	return;
}
TYPED_TEST(DataTransformTest, TestCropSize) {
    TransformationParameter transform_param;
    const bool unique_pixels = false;  // all pixels the same equal to label
    const int label = 0;
    const int channels = 3;
    const int height = 4;
    const int width = 5;
    const int crop_size = 2;

    transform_param.set_crop_size(crop_size);
    Datum datum;
    FillDatum(label, channels, height, width, unique_pixels, &datum);
    DataTransformer<TypeParam> transformer(transform_param, TEST);
    transformer.InitRand();
    Blob<TypeParam> blob(1, channels, crop_size, crop_size);
    for (int iter = 0; iter < this->num_iter_; ++iter) {
        transformer.Transform(datum, &blob);
        EXPECT_EQ(blob.num(), 1);
        EXPECT_EQ(blob.channels(), datum.channels());
        EXPECT_EQ(blob.height(), crop_size);
        EXPECT_EQ(blob.width(), crop_size);
        for (int j = 0; j < blob.count(); ++j) {
            EXPECT_EQ(blob.cpu_data()[j], label);
        }
    }
}
Esempio n. 6
0
void smoke::solver::SourceManager::accumulateSources(smoke::core::SimData* simDataPtr)
{
	accumulateField(simDataPtr->getDensityPtr(), simDataPtr->density_sources);

	accumulateField(simDataPtr->getTemperaturePtr(), simDataPtr->temperature_sources);

	//---------------
	openvdb::VectorGrid::Ptr gridA = simDataPtr->getVelocityPtr();
	std::vector<smoke::sources::VdbVectorSource*>& sources = simDataPtr->velocity_sources;

	for (std::vector<smoke::sources::VdbVectorSource*>::iterator source = sources.begin();
			source != sources.end(); ++source)
	{
		smoke::core::VectorGridPtr sourceGridB = (*source)->getVectorGridPtr();
		openvdb::VectorGrid::Ptr targetGridB = gridA->deepCopy();
		const openvdb::math::Transform &sourceXform = sourceGridB->transform(), &targetXform =
				targetGridB->transform();
		openvdb::Mat4R xform = sourceXform.baseMap()->getAffineMap()->getMat4()
				* targetXform.baseMap()->getAffineMap()->getMat4().inverse();
		openvdb::tools::GridTransformer transformer(xform);
		transformer.transformGrid<openvdb::tools::QuadraticSampler, openvdb::VectorGrid>(
				*sourceGridB, *targetGridB);
		openvdb::tools::compMax(*gridA, *targetGridB);
	}
	sources.clear();

}
Esempio n. 7
0
int main(int argv, char **argc) {
    /*
     Step 1 - Configuration using passed arguments
     +----------------------------+-------------------------+
     | Input parameters           | Requirement             |
     +----------------------------+-------------------------+
     | input data folder          | obligatory              |
     | processes count            | obligatory [DISABLED]   |
     | average life span          | obligatory [DISABLED]   |
     | year loop count            | obligatory [DISABLED]   |
     | result folder              | optional   [DISABLED]   |
     | log file                   | optional   [DISABLED]   |
     +----------------------------+-------------------------+
     */
    if (argv < 2 ) {
        printf("incorrect usage: incorrect amount of arguments (%d < 2)\n", argv);
        return 1;
    }

    /*
     Step 2 - setup world
     Launch and initialize required processes.
     Open communication sockets.
     Setup primal database.
     */
    communicator = Communicator::getInstance(true,"WORLD");
    primal = Primal::getInstance(MSG_DEBUG2);
    Transformer transformer(MSG_DEBUG3);

    communicator->CreateListenSocket(argc[1]);
    communicator->setTransformer(&transformer);

    primal->getInputFileList(argc[2]);

    /*
     Step 3 - setup first generation [DISABLED]
     First generation will be the first organism objects compiled, after this they only have to be managed with
     communication trough watchdog. Organisms shall spawn their own children.
     */

    /*
     Step 4 - sanity check [DISABLED]
     Check that communication is initialized with all of the first generation organisms.
     Check database block count
     */

    /*
     Step 5 - work
     Make number of loops set up by user and give the results
     */
    do{
        bool ret = communicator->waitForConnection();
        if (!ret ){
            return 1;
        }
    }while(communicator->getClientCount() > 0 );
    delete primal;
    delete communicator;
    return 0;
}
Esempio n. 8
0
string jdmExiste(string s){
    string url="http://www.jeuxdemots.org/autocompletion/autocompletion.php?completionarg=proposition&proposition=";
    url+=s;
    url = transformer(&url," ","%20");

    int i=0;
    string result;
    if(lireMot(&i, &s, "/"))
        result = ouvrirPageForce(url);
    else
        result = ouvrirPage(url);

    i=0;
    string candidat;
    lireMot(&i, &result, "[\"");
    string maxs="";
    int maxi=10;
    while(lireMot(&i, &result, &candidat, "\"")){
        if( maxi<(poidJDM(candidat)/pow(LevenshteinDistance(s, candidat),3)) ){
            maxi=poidJDM(candidat)/pow(LevenshteinDistance(s, candidat),3);
            maxs=s;
        }
        candidat.clear();
        lireMot(&i, &result, "\"");
    }
    return maxs;
}
    int NumSequenceMatches(const TransformationParameter transform_param,
                           const Datum& datum, Phase phase) {
        // Get crop sequence with Caffe seed 1701.
        DataTransformer<Dtype> transformer(transform_param, phase);
        const int crop_size = transform_param.crop_size();
        Caffe::set_random_seed(seed_);
        transformer.InitRand();
        Blob<Dtype> blob(1, datum.channels(), datum.height(), datum.width());
        if (transform_param.crop_size() > 0) {
            blob.Reshape(1, datum.channels(), crop_size, crop_size);
        }

        vector<vector<Dtype> > crop_sequence;
        for (int iter = 0; iter < this->num_iter_; ++iter) {
            vector<Dtype> iter_crop_sequence;
            transformer.Transform(datum, &blob);
            for (int j = 0; j < blob.count(); ++j) {
                iter_crop_sequence.push_back(blob.cpu_data()[j]);
            }
            crop_sequence.push_back(iter_crop_sequence);
        }
        // Check if the sequence differs from the previous
        int num_sequence_matches = 0;
        for (int iter = 0; iter < this->num_iter_; ++iter) {
            vector<Dtype> iter_crop_sequence = crop_sequence[iter];
            transformer.Transform(datum, &blob);
            for (int j = 0; j < blob.count(); ++j) {
                num_sequence_matches += (crop_sequence[iter][j] == blob.cpu_data()[j]);
            }
        }
        return num_sequence_matches;
    }
Esempio n. 10
0
/*
 * This function will find the four corners of a template image
 */
std::vector<cv::Point> FindTemplateCorners(cv::Mat templ) {
    cv::Mat points;
    std::vector<cv::Point> corners;
    PointDetector pointDetector(templ, MAGIC_THRESHOLD_VALUE, "Template");
    points = pointDetector.DetectPoints(backProjectSample[0]);
    Transformer transformer(points);
    corners = transformer.FindTemplateCorners(points);
    return corners;
}
Esempio n. 11
0
void Graphic31::transform_ (Coord x, Coord y, Coord& tx, Coord& ty, Graphic31* g) {
    Transformer* t = (g == nil) ? transformer() : g->transformer();

    if (t != nil) {
        t->Transform(x, y, tx, ty);
    } else {
        tx = x;
        ty = y;
    }
}
Esempio n. 12
0
void Slider::reallocate_thumb(const Allocation& a) {
    Patch& thumb = *impl_->thumb_patch_;
    Canvas* c = canvas();
    c->push_transform();
    c->transformer(transformer());
    Extension ext;
    ext.clear();
    thumb.allocate(c, a, ext);
    c->pop_transform();
    thumb.redraw();
}
Esempio n. 13
0
inline transform_iterator<filter_iterator<I, FP>, TF> make_transform_filter_iterator(I from, I to, TF fn, FP pr)
{
    typedef ss_typename_param_k FP::result_type  predicate_result_t;

    // If this fires, you've either specified the transforming function and
    // the filtering predicate in the wrong order, or your predicate has a
    // non-integral return type (which would be decidedly odd).
    STLSOFT_STATIC_ASSERT(0 != is_integral_type<predicate_result_t>::value);

    return transformer(filter(from, to, pr), fn);
}
Esempio n. 14
0
vector <string> jdmRel(string mot1, string mot2){
    //mot1.resize(mot1.size()-1);
    mot1=transformer(&mot1," ","%20");
    mot2=transformer(&mot2," ","%20");

    //http://www.jeuxdemots.org/intern_lexical_signature.php?affichrel_submit=Afficher&term_1=Pulp%20fiction&term_2=film
    vector <string> retour;
    string adresse = "http://www.jeuxdemots.org/intern_lexical_signature.php?affichrel_submit=Afficher&term_1=";
    adresse+=latin1(mot1);
    adresse+="&term_2=";
    adresse+=latin1(mot2);
    //cout<<"adresse : "<<adresse<<endl;
    //pause("adresse");
    string page = ouvrirPage(adresse);
    string relTexte = decouperPage(&page,"div","relations");
    int it=0;
    string rel;
    string score;
    while(lireMot(&it, &relTexte, "<br>")){

        it++;
        lireMot(&it, &relTexte, " -- "); //mot1;
        it++;
        lireMot(&it, &relTexte, "_");
        lireMot(&it, &relTexte, &rel , " : ");
        lireMot(&it, &relTexte, &score , " -->");

        if(atoi(score.c_str())>20){
            retour.push_back(rel);
        }
        //cout<<score<<endl;
        //cout<<atoi(score.c_str())<<endl;
        //cout<<rel<<endl;
        //pause("score");
        score.clear();
        rel.clear();
        //pause("relation");
    }
    return retour;
    //string = decouperPage(&c,"div","relations",&it);
}
Esempio n. 15
0
CFX_DIBitmap* CFX_DIBSource::TransformTo(const CFX_Matrix* pDestMatrix,
                                         int& result_left,
                                         int& result_top,
                                         uint32_t flags,
                                         const FX_RECT* pDestClip) const {
  CFX_ImageTransformer transformer(this, pDestMatrix, flags, pDestClip);
  transformer.Start();
  transformer.Continue(nullptr);
  result_left = transformer.result().left;
  result_top = transformer.result().top;
  return transformer.DetachBitmap().release();
}
Esempio n. 16
0
void FAST_FUNC open_transformer(int fd, const char *transform_prog)
#endif
{
	struct fd_pair fd_pipe;
	int pid;

	xpiped_pair(fd_pipe);
	pid = BB_MMU ? xfork() : xvfork();
	if (pid == 0) {
		/* Child */
		close(fd_pipe.rd); /* we don't want to read from the parent */
		// FIXME: error check?
#if BB_MMU
		{
			transformer_aux_data_t aux;
			init_transformer_aux_data(&aux);
			aux.check_signature = check_signature;
			transformer(&aux, fd, fd_pipe.wr);
			if (ENABLE_FEATURE_CLEAN_UP) {
				close(fd_pipe.wr); /* send EOF */
				close(fd);
			}
			/* must be _exit! bug was actually seen here */
			_exit(EXIT_SUCCESS);
		}
#else
		{
			char *argv[4];
			xmove_fd(fd, 0);
			xmove_fd(fd_pipe.wr, 1);
			argv[0] = (char*)transform_prog;
			argv[1] = (char*)"-cf";
			argv[2] = (char*)"-";
			argv[3] = NULL;
			BB_EXECVP(transform_prog, argv);
			bb_perror_msg_and_die("can't execute '%s'", transform_prog);
		}
#endif
		/* notreached */
	}

	/* parent process */
	close(fd_pipe.wr); /* don't want to write to the child */
	xmove_fd(fd_pipe.rd, fd);
}
Esempio n. 17
0
void Slider::drag(const Event& e) {
    SliderImpl& s = *impl_;
    if (!s.aborted_ && s.dragging_) {
        if (!s.showing_old_thumb_ && s.old_thumb_ != nil) {
            s.showing_old_thumb_ = true;
            Patch* p = s.thumb_patch_;
            Canvas* c = canvas();
            c->push_transform();
            c->transformer(transformer());
            Extension ext;
            ext.clear();
            s.old_thumb_->allocate(c, p->allocation(), ext);
            c->pop_transform();
        }
        Coord x, y;
        s.get_position(this, e, x, y);
        move_to(x - s.xoffset_, y - s.yoffset_);
    }
}
Esempio n. 18
0
void smoke::solver::SourceManager::accumulateField(const smoke::core::FloatGridPtr& gridA,
		std::vector<smoke::sources::VdbFloatSource*>& sources)
{
	for (std::vector<smoke::sources::VdbFloatSource*>::iterator source = sources.begin();
			source != sources.end(); ++source)
	{
		smoke::core::FloatGridPtr sourceGridB = (*source)->getFloatGridPtr();
		openvdb::FloatGrid::Ptr targetGridB = gridA->deepCopy();
		const openvdb::math::Transform &sourceXform = sourceGridB->transform(), &targetXform =
				targetGridB->transform();
		openvdb::Mat4R xform = sourceXform.baseMap()->getAffineMap()->getMat4()
				* targetXform.baseMap()->getAffineMap()->getMat4().inverse();
		openvdb::tools::GridTransformer transformer(xform);
		transformer.transformGrid<openvdb::tools::QuadraticSampler, openvdb::FloatGrid>(
				*sourceGridB, *targetGridB);
		openvdb::tools::compMax(*gridA, *targetGridB);
	}
	sources.clear();
}
Esempio n. 19
0
void XsltTransformViewer::onLoad()
{
	ViewerBase::onLoad();

	shared_ptr<XMLNode> root = getModuleDocument()->getRoot();
	if(root != nullptr)
	{
		String xmlStr = root->getAttributeString(OS_MODULES_XSLTTRANSFORM_XML);
		String xslStr = root->getAttributeString(OS_MODULES_XSLTTRANSFORM_XSL);
		String xsdStr = root->getAttributeString(OS_MODULES_XSLTTRANSFORM_XSD);

		shared_ptr<XMLDocument> document;

		if(xsdStr.empty())
		{
			document.reset(OS_NEW XMLDocument());
		}
		else
		{
			shared_ptr<XMLSchema> xsd(OS_NEW XMLSchema());
			xsd->parseString(xsdStr);

			document.reset(OS_NEW XMLDocument(xsd));
		}

		if(document->parseString(xmlStr))
		{
			shared_ptr<XMLStylesheet> transformer(OS_NEW XMLStylesheet());
			// Inizializza le funzioni del template
			getPage()->initStylesheet(transformer);

			if(transformer->parseString(xslStr))
			{
				String output;
				if(transformer->applyToString(document, output))
				{
					getControls()->add(shared_ptr<HtmlLiteral>(OS_NEW HtmlLiteral(getPage()->parseOml(output, true, false, false, omlRenderModeOsiris, getInstance().getString()))));
				}
			}
		}
	}
}
Esempio n. 20
0
TYPED_TEST(DataTransformTest, TestMeanValue) {
    TransformationParameter transform_param;
    const bool unique_pixels = false;  // pixels are equal to label
    const int label = 0;
    const int channels = 3;
    const int height = 4;
    const int width = 5;
    const int mean_value = 2;

    transform_param.add_mean_value(mean_value);
    Datum datum;
    FillDatum(label, channels, height, width, unique_pixels, &datum);
    Blob<TypeParam> blob(1, channels, height, width);
    DataTransformer<TypeParam> transformer(transform_param, TEST);
    transformer.InitRand();
    transformer.Transform(datum, &blob);
    for (int j = 0; j < blob.count(); ++j) {
        EXPECT_EQ(blob.cpu_data()[j], label - mean_value);
    }
}
Esempio n. 21
0
    static inline bool apply(Polygon const& poly, Point& centroid,
                             Strategy const& strategy)
    {
        if (range_ok(exterior_ring(poly), centroid))
        {
            // prepare translation transformer
            translating_transformer<Polygon>
                transformer(*boost::begin(exterior_ring(poly)));
            
            typename Strategy::state_type state;
            centroid_polygon_state::apply(poly, transformer, strategy, state);
            
            if ( strategy.result(state, centroid) )
            {
                // translate the result back
                transformer.apply_reverse(centroid);
                return true;
            }
        }

        return false;
    }
Esempio n. 22
0
TYPED_TEST(DataTransformTest, TestEmptyTransformUniquePixels) {
    TransformationParameter transform_param;
    const bool unique_pixels = true;  // pixels are consecutive ints [0,size]
    const int label = 0;
    const int channels = 3;
    const int height = 4;
    const int width = 5;

    Datum datum;
    FillDatum(label, channels, height, width, unique_pixels, &datum);
    Blob<TypeParam> blob(1, 3, 4, 5);
    DataTransformer<TypeParam> transformer(transform_param, TEST);
    transformer.InitRand();
    transformer.Transform(datum, &blob);
    EXPECT_EQ(blob.num(), 1);
    EXPECT_EQ(blob.channels(), datum.channels());
    EXPECT_EQ(blob.height(), datum.height());
    EXPECT_EQ(blob.width(), datum.width());
    for (int j = 0; j < blob.count(); ++j) {
        EXPECT_EQ(blob.cpu_data()[j], j);
    }
}
Esempio n. 23
0
    static inline bool apply(Range const& range, Point& centroid,
                             Strategy const& strategy)
    {
        if (range_ok(range, centroid))
        {
            // prepare translation transformer
            translating_transformer<Range> transformer(*boost::begin(range));
            
            typename Strategy::state_type state;
            centroid_range_state<Closure>::apply(range, transformer,
                                                 strategy, state);
            
            if ( strategy.result(state, centroid) )
            {
                // translate the result back
                transformer.apply_reverse(centroid);
                return true;
            }
        }

        return false;
    }
Esempio n. 24
0
bool QgsProperty::convertToTransformer()
{
  if ( d->type != ExpressionBasedProperty )
    return false;

  if ( d->transformer )
    return false; // already a transformer

  QString baseExpression;
  QString fieldName;
  std::unique_ptr< QgsPropertyTransformer > transformer( QgsPropertyTransformer::fromExpression( d->expressionString, baseExpression, fieldName ) );
  if ( !transformer )
    return false;

  d.detach();
  d->transformer = transformer.release();
  if ( !fieldName.isEmpty() )
    setField( fieldName );
  else
    setExpressionString( baseExpression );
  return true;
}
Esempio n. 25
0
void layer_raster::draw(const std::vector<brig::variant>& row, const frame& fr, QPainter& painter)
{
  if (row.size() < 2|| row[0].type() != typeid(brig::blob_t)) return;
  const brig::blob_t& g(boost::get<brig::blob_t>(row[0]));
  const QRectF rect_rast(box_to_rect(brig::boost::envelope(brig::boost::geom_from_wkb(g)))); // todo: rotated raster
  QImage img_rast;
  if (row[1].type() != typeid(brig::blob_t)) return;
  const brig::blob_t& r(boost::get<brig::blob_t>(row[1]));
  if (!img_rast.loadFromData(r.data(), uint(r.size()))) return;
  projection pj_rast(get_pj());
  projection pj_fr(fr.get_pj());
  if (pj_rast == pj_fr)
    painter.drawImage(fr.proj_to_pixel(rect_rast).toAlignedRect(), img_rast);
  else
  {
    const QRectF rect_fr(transformer(pj_rast, pj_fr).transform(rect_rast));
    const QRect rect_fr_px(fr.proj_to_pixel(fr.prepare_rect().intersected(rect_fr)).toAlignedRect());
    if (!rect_fr_px.isValid()) return;
    QImage img_fr(rect_fr_px.size(), QImage::Format_ARGB32_Premultiplied);
    transformer tr(pj_fr, pj_rast);
    for (int j(0); j < img_fr.height(); ++j)
      for (int i(0); i < img_fr.width(); ++i)
      {
        const QPointF point_fr(static_cast<brig::qt::frame>(fr).pixel_to_proj(rect_fr_px.topLeft() + QPoint(i, j)));
        const QPointF point_rast(tr.transform(point_fr));
        if (rect_rast.contains(point_rast))
        {
          const double dx((point_rast.x() - rect_rast.left()) / rect_rast.width());
          const double dy((point_rast.y() - rect_rast.top()) / rect_rast.height());
          auto pixel(img_rast.pixel(int(dx * img_rast.width()), int((1 - dy) * img_rast.height())));
          img_fr.setPixel(i, j, pixel);
        }
        else
          img_fr.setPixel(i, j, QColor(0, 0, 0, 0).rgba());
      }
    painter.drawImage(rect_fr_px, img_fr);
  }
}
Esempio n. 26
0
TYPED_TEST(DataTransformTest, TestMeanValues) {
    TransformationParameter transform_param;
    const bool unique_pixels = false;  // pixels are equal to label
    const int label = 0;
    const int channels = 3;
    const int height = 4;
    const int width = 5;

    transform_param.add_mean_value(0);
    transform_param.add_mean_value(1);
    transform_param.add_mean_value(2);
    Datum datum;
    FillDatum(label, channels, height, width, unique_pixels, &datum);
    Blob<TypeParam> blob(1, channels, height, width);
    DataTransformer<TypeParam> transformer(transform_param, TEST);
    transformer.InitRand();
    transformer.Transform(datum, &blob);
    for (int c = 0; c < channels; ++c) {
        for (int j = 0; j < height * width; ++j) {
            EXPECT_EQ(blob.cpu_data()[blob.offset(0, c) + j], label - c);
        }
    }
}
Esempio n. 27
0
TYPED_TEST(DataTransformTest, TestMeanFile) {
    TransformationParameter transform_param;
    const bool unique_pixels = true;  // pixels are consecutive ints [0,size]
    const int label = 0;
    const int channels = 3;
    const int height = 4;
    const int width = 5;
    const int size = channels * height * width;

    // Create a mean file
    string mean_file;
    MakeTempFilename(&mean_file);
    BlobProto blob_mean;
    blob_mean.set_num(1);
    blob_mean.set_channels(channels);
    blob_mean.set_height(height);
    blob_mean.set_width(width);

    for (int j = 0; j < size; ++j) {
        blob_mean.add_data(j);
    }

    LOG(INFO) << "Using temporary mean_file " << mean_file;
    WriteProtoToBinaryFile(blob_mean, mean_file);

    transform_param.set_mean_file(mean_file);
    Datum datum;
    FillDatum(label, channels, height, width, unique_pixels, &datum);
    Blob<TypeParam> blob(1, channels, height, width);
    DataTransformer<TypeParam> transformer(transform_param, TEST);
    transformer.InitRand();
    transformer.Transform(datum, &blob);
    for (int j = 0; j < blob.count(); ++j) {
        EXPECT_EQ(blob.cpu_data()[j], 0);
    }
}
Esempio n. 28
0
	inline transformer dummy() {
		return transformer( detail::abstract_transformer_backend_ptr(new detail::dummy_transformer_backend) );
	}
Esempio n. 29
0
	inline transformer mk(parsing::parseme::id_t id) {
		return transformer( detail::abstract_transformer_backend_ptr(new detail::mk_transformer_backend(id)) );
	}
Esempio n. 30
0
	transformer operator , (const transformer& lhs, const walking::placeholder<I>& rhs) {
		detail::abstract_transformer_backend_ptr new_lhs = sooty::common::detail::clone_tree(lhs.backend);
		sooty::common::detail::append_success(new_lhs, detail::link_t(detail::insert_backend(I), detail::how_to_traverse::next_sibling));
		return transformer(new_lhs);
	}