Ejemplo n.º 1
0
// Recursively print the hierarchy starting from the root.
// If there is only one aggregate object, the hierarchy will
// only be one level deep (i.e. the children of the one
// aggregate).  However, if there are other aggregates nested 
// within the top one, the printer will print each nested
// aggregate with further indentation.
void printer::print_it( std::ostream &out, Object *root )
    {
    if( root == NULL ) return;
    if( root->PluginType() == aggregate_plugin )
        {
        Aggregate *agg = (Aggregate *)root;
        out << indent() << "begin " << root->MyName() << endl;
        indent_n += 4;
        agg->Begin();
        for( int n = 0;  ; n++ )
            {
            Object *obj = agg->GetChild();
            if( obj == NULL ) break;
            if( limit > 0 && n == limit )
                {
                // Indicate that the list has been truncated.
                out << indent() << "..." << endl;
                break;
                }
            else print_it( out, obj );
            }
        indent_n -= 4;
        out << indent() << "end" << endl;
        }
    else if( root->PluginType() == primitive_plugin )
        {
        out << indent() << root->MyName() << endl;
        }
    }
Ejemplo n.º 2
0
// appends to the current aggregate a slice from a given aggregate from position i1 to position i2
void Aggregate::insertSlice(Aggregate a,Word pos,Word i1,Word i2){
	ADJUSTOFFSET(elements(),pos);ADJUSTOFFSET2(a.elements(),i1,i2);assert0(i1<=i2,"appendSlice");
	Word sz=i2-i1;checkResize(sz);
	elements(elements()+sz);
	WordMove(dataP()+pos+sz,dataP()+pos,elements()-pos);
	WordCpy(dataP()+pos,a.dataP()+i1,sz);
}
Ejemplo n.º 3
0
AggregateOrdered ET::match(const Aggregate s,AggregateOrdered positions, Obj pat,AggregateOrdered r){
	SWITCHstart
		CASEIF(pat.isInstanceOf(classInt))
			uWord sn=s.elements();
// looping on the positions 
// if a position is between start and end and the pattern equals 
// the value at pos then add the next position to the results.
			for(auto p:positions){
				if(0<=p && p<sn && pat.w==s[p]) 
					r&=p+1; //&= adds a single object to an ordered aggregate (if it doesn't exists already)
			}
		CASEIF(pat.isInstanceOf(classDouble))
			uWord sn=s.elements();
			for(auto p:positions){
				if(0<=p && p<sn && compare(pat,s[p])==0) 
					r&=p+1; //&= adds a single object to an ordered aggregate (if it doesn't exists already)
			}
		CASEIF(pat.isInstanceOf(classPatternAll))
			AggregateOrdered r1=positions;
			for(auto pat1:(Aggregate)pat)
				r1=match(s,r1,pat1);
			if(r.elements()==0) r=r1;else r+=r1;
		CASEIF(pat.isInstanceOf(classPatternAny))
			for(auto pat1:(Aggregate)pat)
				match(s,positions,pat1,r);
		CASEIF(pat.isInstanceOf(classAggregate))
			stack().push(positions);
			execute(pat,true); // should execute independently from the execution status ? should be explained !
			r=stack().pop();
		DEFAULT
			assert0(false,"unexpected in matchAll");
	endSWITCH
	return r;
}
Ejemplo n.º 4
0
int main() {
    
    Persona p1(20);
    Persona p2(30);
    Aggregate<Persona> lista;
    lista.add(p1);
    lista.add(p2);
    
    for (Iterator<Persona> i = lista.getIterator(); ; ) {
        
    }
    
    return 0;
}
Ejemplo n.º 5
0
// Count the number of objects (either just primitives, or both primitives
// and aggregates) contained in a scene graph.
int CountObjects( const Object *root, bool just_primitives )
    {
    if( root == NULL ) return 0;
    if( root->PluginType() != aggregate_plugin ) return 1;
    Aggregate *agg = (Aggregate *)root;
    agg->Begin();
    int count = ( just_primitives ? 0 : 1 );
    for(;;)
        {
        Object *obj = agg->GetChild();
        if( obj == NULL ) break;
        count += CountObjects( obj, just_primitives );
        }
    return count;
    }
Ejemplo n.º 6
0
  Aggregate*
  Definition::FindAggregate ( uint32_t hash )
  {
    for ( uint32_t i = 0; i < m_NumAggregates; i++ )
    {
      Aggregate* aggregate = ( *this ) [i];

      if ( aggregate->GetNameHash() == hash )
      {
        return aggregate;
      }
    }

    return 0;
  }
Ejemplo n.º 7
0
					void Client::someOperation()
					{
						std::string names[3] = {"张三","李四","王五"};
						//创建聚合对象
						Aggregate *aggregate = new ConcreteAggregate(names);
						//循环输出聚合对象中的值
						Iterator it = aggregate->createIterator();
						//首先设置迭代器到第一个元素
						it->first();
						while(!it->isDone())
						{
							//取出当前的元素来
							object *obj = it->currentItem();
							puts("the obj=="+obj);
							//如果还没有迭代到最后,那么就向下迭代一个
							it->next();
						}
					}
Ejemplo n.º 8
0
int main(int argc, const char * argv[]) {
    FabricaFisica * aguascalientes;
    FabricaFisica * cdmx;
    
    Pastel * leches = aguascalientes->crearPastel("tresleches");
    leches->setNombre("pastelito");
    
    Pastel * sach = cdmx->crearPastel("sacher");
    leches->setNombre("pastelote");
    
    Pastel * impo = cdmx->crearPastel("imposible");
    leches->setNombre("impozzible");
    
    Pastel * choco = cdmx->crearPastel("chocolate");
    
    //Clonado
    Pastel * nueva;
    nueva = leches->clonar();
    nueva->empaquetado();
    
    //Aggregate e iterador
    Aggregate <Pastel*> pastelesAguascalientes;
    pastelesAguascalientes.add(leches);
    
    Aggregate <Pastel*> pastelesCDMX;
    pastelesCDMX.add(leches);
    pastelesCDMX.add(impo);
    
    Iterator<Pastel *> * iterador;
    /*
    for(iterador = pastelesCDMX.getIterator(); iterador->hasNext(); )
    {
        iterador->next()->amasado();
    }
     */
    iterador->imprimirPasteles(pastelesCDMX);
    iterador->buscarPastel("impozzible", pastelesCDMX);
    
    return 0;
}
Ejemplo n.º 9
0
int main()
{
    Aggregate* pAggregate = new ConcreateAggregate(4);
    /*
    Iterater* pIterater = new ConcreateIterater(pAggregate);

    for (; false == pIterater->IsDone(); pIterater->Next())
    {
        std::cout << pIterater->CurrentItem() << std::endl;


    }

    std::cout << pAggregate->GetItem(0)<< std::endl;
    std::cout << pAggregate->GetItem(1)<< std::endl;
    std::cout << pAggregate->GetItem(2)<< std::endl;
    std::cout << pAggregate->GetItem(3)<< std::endl;

    std::cout << pAggregate->GetSize()<< std::endl;
*/
    /*用法比较犀利*/
    Iterater* pIterater = pAggregate->CreateIterater(pAggregate);

    for (; false == pIterater->IsDone(); pIterater->Next())
    {
        std::cout << pIterater->CurrentItem() << std::endl;


    }

    std::cout << pAggregate->GetItem(0)<< std::endl;
    std::cout << pAggregate->GetItem(1)<< std::endl;
    std::cout << pAggregate->GetItem(2)<< std::endl;
    std::cout << pAggregate->GetItem(3)<< std::endl;

    std::cout << pAggregate->GetSize()<< std::endl;
    return 0;
}
Ejemplo n.º 10
0
/**
 * From P <=> Agg
 * go to
 *
 * P <=> (Pnew | M1) & M2
 * Pnew <=> Agg
 * and M1 assumed false, M2 assumed true
 */
void OneShotUnsatCoreExtraction::add(const Aggregate& agg) {
	Aggregate extended(agg);
	auto oldhead = extended.head;
	auto newhead = getRemapper()->getNewVar();
	auto truemarker = getRemapper()->getNewVar();
	auto falsemarker = getRemapper()->getNewVar();
	auto tseitin = getRemapper()->getNewVar();
	extended.head = mkPosLit(newhead);
	switch (agg.sem) {
	case AggSem::DEF: {
		Rule impl(agg.getID(), tseitin, { mkPosLit(newhead), mkPosLit(falsemarker) }, false, agg.defID, agg.onlyif);
		Rule impl2(agg.getID(), var(oldhead), { mkPosLit(tseitin), mkPosLit(truemarker) }, true, agg.defID, agg.onlyif);
		space->add(impl);
		space->add(impl2);
		break;
	}
	case AggSem::COMP: {
		Implication impl(agg.getID(), mkPosLit(tseitin), ImplicationType::EQUIVALENT, { mkPosLit(newhead), mkPosLit(falsemarker) }, false);
		Implication impl2(agg.getID(), oldhead, ImplicationType::EQUIVALENT, { mkPosLit(tseitin), mkPosLit(truemarker) }, true);
		space->add(impl);
		space->add(impl2);
		break;
	}
	case AggSem::OR: {
		Implication impl2(agg.getID(), ~oldhead, ImplicationType::IMPLIES, { mkPosLit(newhead), mkPosLit(falsemarker) }, false);
		space->add(impl2);
		break;
	}
	}
	markerAssumptions.push_back(mkNegLit(falsemarker));
	markerAssumptions.push_back(mkPosLit(truemarker));
	id2constr[agg.getID()] = new Aggregate(agg);
	marker2ids[truemarker].push_back(agg.getID());
	marker2ids[falsemarker].push_back(agg.getID());
	space->add(extended);

}
Ejemplo n.º 11
0
AggregateOrdered match(const Aggregate s,AggregateOrdered positions, Obj pat,AggregateOrdered r=0,Word pn=1){
// p holds the positions array that may have 1 or 2 columns per raw
#define loop(aa,step) for(Word i=0,i1=aa.elements(),p;i<i1 && (p=aa[i],true);i+=step)
	
	switch(pat.Class().w){
		case _classInt:{
			if(!r) 
				r=AggregateOrdered();
			uWord sn=s.elements();
			loop(positions,pn){
				if(0<=p && p+1<=sn && s[p]==pat.w) r.keyExists((Obj)(p+1));
			}
		};
		break;
		case _classAggregate:
			stack.push(positions);
			execute(pat,true);
			r=stack.pop();
			break;
		case _classString:
		case _classPatternAll:{
			AggregateOrdered r1=positions;
			for(auto pat1:(Aggregate)pat)
				r1=match(s,r1,pat1);
			if(!r) r=r1;else r+=r1;
			break;
		}
		case _classPatternAny:
			if(!r) 
				r=AggregateOrdered();
			for(auto pat1:(Aggregate)pat)
				match(s,positions,pat1,r);
			break;
		default:
			assert0(false,"unexpected in matchAll");
			break;
	}
	return r;
}
Ejemplo n.º 12
0
AggregateOrdered ET::matchEnd(Aggregate s,AggregateOrdered positions){
	AggregateOrdered r;
	if(positions.keyExists(s.elements(),false))
		r.push(s.elements());
	return r;
}
Ejemplo n.º 13
0
Aggregate ET::allPos(Aggregate s,Word startPos){
	uWord sn=s.elements(),n=(startPos<=sn?sn-startPos:0);
	Aggregate r(n,n);
	for(uWord i=0,j=startPos;i<n;i++,j++) r[i]=j;
	return r;
}
Ejemplo n.º 14
0
	Scene(Aggregate* aggregate, const vector<Light *> & lights) 
		: aggregate(aggregate), lights(lights), bound(aggregate->world_bound()) {
		//if (volumeRegion) bound = Union(bound, volumeRegion->WorldBound());
	};
bool basic_builder::BuildScene( string file_name, Camera &camera, Scene &scene ) const
    {
    int line_num = 0;
    char input_line[512];
    Plugin    *dat = NULL;  // A container for arbitrary data.
    Object    *obj = NULL;  // The current object, which was the last object created.
    Shader    *shd = NULL;  // The current shader. 
    Aggregate *agg = NULL;  // Current aggregate object, to which all objects are now added.
    Envmap    *env = NULL;  // Current environment map.
    Material  *mat = NULL;  // Current material pointer.
    Material   material;    // Current material.

    scene.object    = NULL;
    scene.envmap    = NULL;
    scene.rasterize = NULL;

    // Attempt to open the input file.

    file_name += ".sdf";
    std::ifstream fin;
    fin.open( file_name.c_str() );
    if( fin.fail() )
        {
        cerr << "Error: Could not open file " << file_name << endl;
        return false;  // Report failure.
        }
    cout << "Reading " << file_name << "... ";
    cout.flush();

    // Set some defaults.

    material.diffuse      = White;
    material.emission     = Black;
    material.specular     = White;
    material.ambient      = Black;
    material.reflectivity = Black;
    material.translucency = Black;
    material.ref_index    = 0.0;
    material.Phong_exp    = 0.0;

    camera.x_res = default_image_width;
    camera.y_res = default_image_height;
    camera.x_win = Interval( -1.0, 1.0 );
    camera.y_win = Interval( -1.0, 1.0 );

    // Process lines until the end of file is reached.
    // Print a warning for all lines that are unrecognizable.

    while( fin.getline( input_line, 512 ) ) 
        {
        line_num++;
        if( Skip( input_line ) ) continue;

        // Ask each registered object if it recognizes the line.  If it does, it will
        // create a new instance of the object and return it as the function value.

        Plugin *plg = Instance_of_Plugin( input_line );

        if( plg != NULL )
            {
            switch( plg->PluginType() )
                {
                case data_plugin:
                    if( obj == NULL ) cerr << "Error: data ignored.  Line " << line_num << endl;
                    else obj->AddData( obj );
                    break;

                case shader_plugin:
                    shd = (Shader*)plg;
                    break;					
 
                case aggregate_plugin:
                    obj = (Object*)plg;
                    obj->shader   = shd;
                    obj->envmap   = env;
                    obj->material = Copy( mat, material );
                    obj->parent   = agg;
                    if( Emitter( material ) )
                        {
                        cerr << "Error: An aggregate object cannot be an emitter.  Line "
                             << line_num << ": "
                             << input_line << endl;
                        return false;
                        }
                    if( agg != NULL ) // If there is alrealy an agg obj, this one is a child.
                        {
                        // agg->AddChild( obj );
                        // Do not add aggregates as children until they are complete.
                        agg->material = Copy( mat, material );
                        }
                    else if( scene.object == NULL ) scene.object = obj;
	            agg = (Aggregate *)obj;
                    break;

                case primitive_plugin:
                    obj = (Object*)plg;
                    obj->shader   = shd;
                    obj->envmap   = env;
                    obj->material = Copy( mat, material );
                    obj->parent   = agg;
                    if( Emitter( material ) ) scene.lights.push_back( obj );
                    if( agg != NULL )
                        {
                        agg->AddChild( obj );
                        agg->material = Copy( mat, material );
                        }
                    else if( scene.object == NULL ) scene.object = obj;
                    break;

                case envmap_plugin:
                    env = (Envmap*)plg;
                    // If an environment map is set before any object is created, use it as
                    // the background.
                    if( obj == NULL ) scene.envmap = env;
                    break;

                case rasterizer_plugin:
                    if( scene.rasterize != NULL )
                        {
                         cerr << "Error: More than one rasterizer specified.  Line "
                             << line_num << ": "
                             << input_line << endl;
                        return false;
                        }
                    scene.rasterize = (Rasterizer *)plg;
                    break;
                } 
            continue;
            }

        // Now look for all the other stuff...  materials, camera, lights, etc.

        ParamReader get( input_line );
 
        if( get["eye"]          && get[camera.eye]            ) continue;
        if( get["lookat"]       && get[camera.lookat]         ) continue;            
        if( get["up"]           && get[camera.up]             ) continue;            
        if( get["vpdist"]       && get[camera.vpdist]         ) continue;                   
        if( get["x_res"]        && get[camera.x_res]          ) continue;
        if( get["y_res"]        && get[camera.y_res]          ) continue;
        if( get["x_win"]        && get[camera.x_win]          ) continue;
        if( get["y_win"]        && get[camera.y_win]          ) continue;
        if( get["ambient"]      && get[material.ambient]      ) continue;            
        if( get["diffuse"]      && get[material.diffuse]      ) continue;
        if( get["specular"]     && get[material.specular]     ) continue;
        if( get["emission"]     && get[material.emission]     ) continue;
        if( get["reflectivity"] && get[material.reflectivity] ) continue;
        if( get["translucency"] && get[material.translucency] ) continue;
        if( get["Phong_exp"]    && get[material.Phong_exp]    ) continue;
        if( get["ref_index"]    && get[material.ref_index]    ) continue;

        // If no object is defined at this point, it's an error.

        if( obj == NULL )
            {
            cerr << "Error reading scene file; No object defined at line "
                 << line_num << ": "
                 << input_line << endl;
            return false;
            }

        // Look for an end statement that closes the current aggregate.  This allows us to nest aggregates.

        if( get["end"] )
            { 
            if( agg == NULL )
                {
                cerr << "Error: end statement found outside an aggregate object at line "
                     << line_num << ": "
                     << input_line << endl;
                return false;
                }
            
            // Go back to adding objects to the parent object (if there is one).

            agg->Close(); // Signal the aggregate that it is now complete.
            Object *closed_agg = agg;
            agg = agg->parent;
            if( agg != NULL )
                {
                material = *(agg->material);
                mat = agg->material;
                shd = agg->shader;
                env = agg->envmap;
                agg->AddChild( closed_agg ); // Add the agg that just ended.
                }
            continue;
            }
        
        // If nothing matched, it's an error.  Print a warning and continue processing.

        cerr << "Warning: Unrecognized or ill-formed command at line "
             << line_num << ": "
             << input_line << endl;
        }

    if( agg != NULL )
        {
        cerr << "Error: Top-most aggregate object has no 'end' statement." << endl;
        return false;
        }

    cout << "done." << endl;
    return true;
    }
Ejemplo n.º 16
0
Aggregate allPos(Aggregate s){
	uWord sn=s.elements();Aggregate r(sn,sn);
	for(uWord i=0;i<s.elements();i++) r[i]=i;
	return r;
}
Ejemplo n.º 17
0
void ResultSet::aggregate(const std::string& prefix,
                          const std::string& filename) {
  // Parse prefix
  char* prefix_data = strdup(prefix.data());
  char* reason          = strtok(prefix_data, "/");
  char* appName         = strtok(NULL, "/");
  char* channel         = strtok(NULL, "/");
  char* version         = strtok(NULL, "/");
  char* strBuildId      = strtok(NULL, ".");
  char* submissionDate  = strtok(NULL, ".");
  if (!reason || !appName || !channel || !version || !strBuildId ||
      !submissionDate) {
    fprintf(stderr, "Prefix '%s' missing parts \n", prefix.data());
    free(prefix_data);
    return;
  }
  // Intern strBuildId
  InternedString buildId = Aggregate::internBuildIdString(strBuildId);

  // Get build date, ignore the rest
  if (strlen(strBuildId) < 8) {
    fprintf(stderr, "BuildId '%s' is not valid, too short\n", strBuildId);
    free(prefix_data);
    return;
  }
  string buildDate(strBuildId, 8);

  // Decide if we should skip submission date
  bool skipBySubmissionDate = false;
  {
    // Parse submission date and buildDate
    time_t submissionTime = parseDate(submissionDate);
    time_t buildTime      = parseDate(buildDate.data());

    // Skip aggregation by submission date of it's been more than 60 days since
    // build date
    if (difftime(submissionTime, buildTime) > 60 * 60 * 24 * 60) {
      skipBySubmissionDate = true;
    }
  }

  // Reduce version to major version (discard everything after the dot)
  {
    char* c = version;
    while(*c != '.' && *c != '\0') c++;
    *c = '\0';
  }

  // Find/create ChannelVersion object
  ChannelVersion* cv = nullptr;
  {
    string channelVersion = string(channel) + "/" + string(version);
    // Find channel version in hash table
    auto it = _channelVersionMap.find(channelVersion);
    // If not present create ChannelVersion
    if (it == _channelVersionMap.end()) {
      cv = new ChannelVersion(_measureStringCtx, _filterStringCtx);
      it = _channelVersionMap.insert({channelVersion, cv}).first;
    }
    cv = it->second;
  }
  assert(cv);

  // Create filterPath start
  string reasonAppName = string(reason) + "/" + string(appName) + "/";

  // Allocate a string to hold <measure>/<by-date-type>
  string measureFilename;
  measureFilename.reserve(2048);

  FILE* input = fopen(filename.data(), "r");
  {
    // Read file line by line
    CompressedFileReader reader(input);
    char* line = nullptr;
    int nb_line = 0;
    while ((line = reader.nextLine()) != nullptr) {
      nb_line++;
      // Find tab
      char* tab = strchr(line, '\t');
      if (!tab) {
        fprintf(stderr, "No tab on line %i\n", nb_line);
        continue;
      }

      // Set tab = \0 creating two C-strings
      *tab = '\0';
      char* uuid = line;
      char* json = tab + 1;

      UNUSED(uuid);

      // Parse the JSON line
      Document d;
      d.Parse<0>(json);

      // Check that we have an object
      if (!d.IsObject()) {
        fprintf(stderr, "JSON root is not an object on line %i\n", nb_line);
        continue;
      }

      // Find the info field
      Value::Member* infoField = d.FindMember("info");
      if (!infoField || !infoField->value.IsObject()) {
        fprintf(stderr, "'info' in payload isn't an object, line %i\n", nb_line);
        continue;
      }
      Value& info = infoField->value;

      // Find OS, osVersion, arch and revision
      Value::Member* osField    = info.FindMember("OS");
      Value::Member* osVerField = info.FindMember("version");
      Value::Member* archField  = info.FindMember("arch");
      Value::Member* revField   = info.FindMember("revision");
      if (!osField || !osField->value.IsString()) {
        fprintf(stderr, "'OS' in 'info' isn't a string\n");
        continue;
      }
      if (!osVerField || !(osVerField->value.IsString() ||
                           osVerField->value.IsNumber())) {
        fprintf(stderr, "'version' in 'info' isn't a string or number\n");
        continue;
      }
      if (!archField || !archField->value.IsString()) {
        fprintf(stderr, "'arch' in 'info' isn't a string\n");
        continue;
      }
      InternedString revision;
      if (revField) {
        if (!revField->value.IsString()) {
          fprintf(stderr, "'revision' in 'info' isn't a string\n");
          continue;
        }
        // Get InternedString for revision
        revision = Aggregate::internRevisionString(revField->value.GetString());
      } else {
        // Get InternedString for revision
        revision = Aggregate::internRevisionString(FALLBACK_REVISION);
      }

      // Create filterPath as <reason>/<appName>/<OS>/<osVersion>/<arch>
      const char* OS = osField->value.GetString();
      string filterPath = reasonAppName + OS;
      filterPath += "/";
      string osVersion;
      if (osVerField->value.IsString()) {
        osVersion = osVerField->value.GetString();
      } else {
        char b[64];
        modp_dtoa2(osVerField->value.GetDouble(), b, 9);
        osVersion = b;
      }
      // For Linux we only add 3 first characters
      if (strcmp(OS, "Linux") == 0) {
        filterPath += osVersion.substr(0, 3);
      } else {
        filterPath += osVersion;
      }
      filterPath += "/";

      // Append arch to filterPath
      filterPath += archField->value.GetString();

      // Aggregate histograms

      Value::Member* hgramField = d.FindMember("histograms");
      if (hgramField && hgramField->value.IsObject()) {
        Value& hgrams = hgramField->value;
        for (auto hgram = hgrams.MemberBegin(); hgram != hgrams.MemberEnd();
                                                                      ++hgram) {
          // Get histogram name and values
          const char* name  = hgram->name.GetString();
          Value& values     = hgram->value;

          // MeasureFilename
          measureFilename = name;
          measureFilename += "/by-build-date";

          // Get measure file
          MeasureFile* mf = cv->measure(measureFilename.data());
          Aggregate*   aggregate = mf->aggregate(buildDate.data(), filterPath.data());

          // Add to aggregate
          aggregate->aggregate(revision, buildId, values);

          // Skip aggregation by submission date, unless requested
          if (skipBySubmissionDate) {
            continue;
          }
          // MeasureFilename
          measureFilename = name;
          measureFilename += "/by-submission-date";

          // Get measure file
          mf = cv->measure(measureFilename.data());
          aggregate = mf->aggregate(submissionDate, filterPath.data());

          // Add to aggregate
          aggregate->aggregate(revision, buildId, values);
        }
      } else {
        fprintf(stderr, "'histograms' of payload isn't an object\n");
      }

      // Aggregate simple measures
      Value::Member* smField = d.FindMember("simpleMeasurements");
      if (smField && smField->value.IsObject()) {
        Value& sms = smField->value;
        for (auto sm = sms.MemberBegin(); sm != sms.MemberEnd(); ++sm) {
          // Get simple measure name and values
          string name   = sm->name.GetString();
          Value& value  = sm->value;

          // Convert name to uppercase
          for(size_t i = 0; i < name.length(); i++) {
            name[i] = toupper(name[i]);
          }

          // Aggregate numbers
          if (value.IsNumber()) {
            // Create measure filename
            measureFilename = "SIMPLE_MEASURES_";
            measureFilename += name;
            measureFilename += "/by-build-date";

            // Get measure file
            MeasureFile* mf = cv->measure(measureFilename.data());
            Aggregate*   aggregate = mf->aggregate(buildDate.data(),
                                                   filterPath.data());

            // Aggregate simple measure
            aggregate->aggregate(value.GetDouble());

            // Aggregate by submission date if desired
            if (!skipBySubmissionDate) {
              // Create measure filename
              measureFilename = "SIMPLE_MEASURES_";
              measureFilename += name;
              measureFilename += "/by-submission-date";

              mf = cv->measure(measureFilename.data());
              aggregate = mf->aggregate(submissionDate, filterPath.data());

              // Aggregate simple measure
              aggregate->aggregate(value.GetDouble());
            }
          } else if (value.IsObject()) {
            // If we have an object read key/values of it
            for (auto ssm = value.MemberBegin(); ssm != value.MemberEnd();
                                                                        ++ssm) {
              string subname   = ssm->name.GetString();
              Value& subvalue  = ssm->value;

              // Convert subname to uppercase
              for(size_t i = 0; i < subname.length(); i++) {
                subname[i] = toupper(subname[i]);
              }

              // Aggregate subvalue, if number, ignore errors there are lots of
              // weird simple measures
              if (subvalue.IsNumber()) {
                // Create measure filename
                measureFilename = "SIMPLE_MEASURES_";
                measureFilename += name;
                measureFilename += "_";
                measureFilename += subname;
                measureFilename += "/by-build-date";

                // Get measure file
                MeasureFile* mf = cv->measure(measureFilename.data());
                Aggregate*   aggregate = mf->aggregate(buildDate.data(),
                                                       filterPath.data());

                // Aggregate simple measure
                aggregate->aggregate(subvalue.GetDouble());

                // Aggregate by submission date if desired
                if (!skipBySubmissionDate) {
                  // Create measure filename
                  measureFilename = "SIMPLE_MEASURES_";
                  measureFilename += name;
                  measureFilename += "_";
                  measureFilename += subname;
                  measureFilename += "/by-submission-date";

                  mf = cv->measure(measureFilename.data());
                  aggregate = mf->aggregate(submissionDate, filterPath.data());

                  // Aggregate simple measure
                  aggregate->aggregate(subvalue.GetDouble());
                }
              }
            }
          }
        }
      }
    }
  }
  fclose(input);

  free(prefix_data);
}
Ejemplo n.º 18
0
	bool intersect(const Ray &ray, Intersection *isect) const {
		return aggregate->intersect(ray, isect);
	}
Ejemplo n.º 19
0
	bool intersect_p(const Ray& ray) const {
		return aggregate->intersect_p(ray);
	}
Ejemplo n.º 20
0
    template <typename TArgs, typename UArgs>
    Aggregate(TArgs t_args, UArgs u_args)
      : t{std::move(t_args).construct()}, u{std::move(u_args).construct()}
    {}

    T const &get_t() const { return t; }
    U const &get_u() const { return u; }

  private:
    T t;
    U u;
  };
}

SCENARIO("basic aggregate") {
  GIVEN("an aggregate type constructed with rvalue tuples") {
    Aggregate<A, B> aggregate{
      mp::builder(mp::construct<A>, "foo", 33)
    , mp::builder(mp::braced_construct<B>, 42, "bar", 77)
    };

    THEN("piecewise construction works") {
      REQUIRE(aggregate.get_t().get_thirty_three() == 33);
      REQUIRE(aggregate.get_t().get_foo() == "foo");
      REQUIRE(aggregate.get_u().forty_two == 42);
      REQUIRE(aggregate.get_u().bar == "bar");
      REQUIRE(aggregate.get_u().seventy_seven == 77);
    }
  }
}
Ejemplo n.º 21
0
void colors(Scene* &scene, Camera* &camera, QtFilm* &film) {
    // Create scene
    scene = new Scene(new ListAggregate());
    *scene << new SkyLight(Spectrum(0xF0FAFF).getColor());

    // Import cornel box
    AssimpImporter importer;
    importer.setDefaultMaterial(Main::matte);
    
    Aggregate* model = new BVHAccelerator();
    
    importer.importModel(model, "/Users/gael/Desktop/Courses/CSE_168/models/scenes/colors.dae", &camera);
    
    std::shared_ptr<Primitive> lightPrimitive = model->findPrimitive("areaLight");
    TransformedPrimitive* lightTransformed = nullptr;
    GeometricPrimitive* lightGeometric = nullptr;
    Mesh* lightShape = nullptr;
    
    if ((lightTransformed = dynamic_cast<TransformedPrimitive*>(lightPrimitive.get()))) {
        if ((lightGeometric
             = dynamic_cast<GeometricPrimitive*>(lightTransformed->getPrimitive().get())))  {
            lightShape = dynamic_cast<Mesh*>(lightGeometric->getShape());
        }
    }
    
    const int numMaterials = 7;
    Glossy* materials[numMaterials];
    for (int i = 0; i < numMaterials; ++i) {
        materials[i] = new Glossy();
        materials[i]->setIndexIn(2.3f);
        materials[i]->setIndexOut(1.0003f);
        materials[i]->setRoughness(0.2f);
    }
    
    materials[0]->setColor(Spectrum(0xFF3D98).getColor());
    materials[1]->setColor(Spectrum(0xABFF3D).getColor());
    materials[2]->setColor(Spectrum(0x3DAEFF).getColor());
    materials[3]->setColor(Spectrum(0xFFA13D).getColor());
    materials[4]->setColor(Spectrum(0x3DDFFF).getColor());
    materials[5]->setColor(Spectrum(0xFF3D3D).getColor());
    materials[6]->setColor(Spectrum(0x3DFFCF).getColor());
    
    // Models
    for (int i = 0; i <= 47; ++i) {
        std::stringstream name;
        
        name << "stand" << i;
        std::shared_ptr<GeometricPrimitive> cube = Main::findPrimitive<GeometricPrimitive>(model, name.str());
        cube->setMaterial(materials[rand() % numMaterials]);
    }    
    
    
    // Create area light using model light shape
    if (lightShape) {
        // Transform light so its triangles are in world space
        const Transform& t = lightTransformed->getTransform();
        
        AreaLight* areaLight = AreaLight::CreateFromMesh(lightShape, t);
        areaLight->setColor(vec3(1.0f, 1.0f, 1.0f));
        areaLight->setIntensity(50.0f);
        lightGeometric->setAreaLight(areaLight);
        *scene << areaLight;
    } else {
        DirectionalLight* light = new DirectionalLight();
        light->setSpectrum(Spectrum(vec3(1.0f, 1.0f, 1.0f)));
        light->setIntensity(2.0f);
        light->setDirection(vec3(2.0f, -3.0f, -2.0f));
        *scene << light;
    }
    
    // Build acceleration structures
    Main::buildAccelerationStructures(model);
    
    *scene << model;
    
    // Create camera
    PerspectiveCamera* perspectiveCamera = nullptr;
    if (!camera) {
        perspectiveCamera = new PerspectiveCamera();
        
        perspectiveCamera->lookAt(vec3(-0.5f, 3.7f, 10.58f), vec3(-0.5f, 3.7f, 9.58f));
    } else {
        perspectiveCamera = dynamic_cast<PerspectiveCamera*>(camera);
        if (!perspectiveCamera) {
            qDebug() << "Wrong camera type";
            abort();
        }
    }
    
    film = new QtFilm(vec2(1280.f, 720.f)/1.0f);
    perspectiveCamera->setFilm(film);
    
    //perspectiveCamera->setVFov(45.f);
    perspectiveCamera->setAspect(film->resolution.x/film->resolution.y);
    
    camera = perspectiveCamera;
}