Ejemplo n.º 1
0
	// Process projected vertices and extract primitives.
	thrust::host_vector<triangle> process_primitives(const mesh & m, thrender::render_context & rstate) {
		thrust::host_vector<triangle> primitives(m.total_triangles());

		thrust::transform(
				m.triangles.begin(), m.triangles.end(),		// Input
				primitives.begin(),							// Output
				primitives_proc_kernel(m.render_buffer.projected_vertices, m, rstate));
		return primitives;
	}
Ejemplo n.º 2
0
int main (void) {
  primitives();

  CPU_PRESCALE(0);
  usb_init();
  while (!usb_configured()) /* wait */ ;

  define_constant("portb", (int)&PORTB);
  define_constant("portd", (int)&PORTD);
  define_constant("portf", (int)&PORTF);

  define_constant("ddrb", (int)&DDRB);
  define_constant("ddrd", (int)&DDRD);
  define_constant("ddrf", (int)&DDRF);

  define_constant("pinb", (int)&PINB);
  define_constant("pind", (int)&PIND);
  define_constant("pinf", (int)&PINF);

  define("pressedkeys", VARIABLE, keyboard_keys);
  define("pressedmodifiers", VARIABLE, &keyboard_modifier_keys);

  define("reset", PRIMITIVE, &reset);
  define("blink", PRIMITIVE, &blink);
  define("blinks", PRIMITIVE, &blinks);
  define("blinq", PRIMITIVE, &blinq);

  define("delaysec", PRIMITIVE, &delaysec);
  define("delay", PRIMITIVE, &delay);
  define("delayten", PRIMITIVE, &delayten);

  define("usbsend", PRIMITIVE, &usbsend);

  define_constant("onboard", 1);

  delaysec();
  input = malloc(81);
  #include "inlined.c"

  delaysec();

  (DDRD |= (1<<6));
  blinq(); blinq(); blinq();
  reset();
};
Ejemplo n.º 3
0
Archivo: main.c Proyecto: jou4/bodhi
int main(int argc, char **argv)
{
    primsigs = primitives();

    Parser ps;
    Lexer lexer;
    FILE *ic, *oc;
    int err = 0;

    getopts(argc, argv);

    ic = fopen(input, "r");
    if(ic == NULL){
        printf("Can not open the file.\n");
        return 1;
    }

    parser_init(&ps);
    lexer_init(&lexer);
    lexer_setin(&lexer, ic);

    err |= yyparse(&ps, &lexer, "input");
    fclose(ic);

    if(proc_compile && err == 0){
        oc = fopen(compiled_file, "w");
        err |= compile(oc, &ps.prog);
        fclose(oc);
    }

    if(proc_assemble && err == 0){
        char cmd[100];
        sprintf(cmd, "gcc -o %s %s -L%s %s", output, compiled_file, libdir, LIBS);
        system(cmd);
    }

    return 0;
}
Ejemplo n.º 4
0
bool KdIntersection::leafIntersectBox(KdTreeNode *node, const BoundingBox & box)
{
	const unsigned num = node->getNumPrims();
	if(num < 1) return false;
	
	if(!box.intersect(m_testBox)) return false;
	
	unsigned start = node->getPrimStart();
	IndexArray &indir = indirection();
	PrimitiveArray &prims = primitives();
	indir.setIndex(start);

	for(unsigned i = 0; i < num; i++) {
		unsigned *iprim = indir.asIndex();

		Primitive * prim = prims.asPrimitive(*iprim);
		Geometry * geo = prim->getGeometry();
		unsigned icomponent = prim->getComponentIndex();
		
		if(geo->intersectBox(icomponent, m_testBox)) return true;
		indir.next();
	}
	return false;
}
Ejemplo n.º 5
0
TEST_F(BPTFullpathTest2, Consistency)
{
	StubConfig config;
	ASSERT_TRUE(config.LoadFromString(TestScenes::Simple03(), ""));

	std::unique_ptr<Assets> assets(ComponentFactory::Create<Assets>());
	ASSERT_TRUE(assets->RegisterInterface<Texture>());
	ASSERT_TRUE(assets->RegisterInterface<BSDF>());
	ASSERT_TRUE(assets->RegisterInterface<TriangleMesh>());
	ASSERT_TRUE(assets->RegisterInterface<Film>());
	ASSERT_TRUE(assets->RegisterInterface<Camera>());
	ASSERT_TRUE(assets->RegisterInterface<Light>());
	ASSERT_TRUE(assets->Load(config.Root().Child("assets")));
	
	std::unique_ptr<Primitives> primitives(ComponentFactory::Create<Primitives>());
	ASSERT_TRUE(primitives->Load(config.Root().Child("scene"), *assets));
	std::unique_ptr<Scene> scene(ComponentFactory::Create<Scene>(config.Root().Child("scene").AttributeValue("type")));
	ASSERT_NE(scene, nullptr);
	scene->Load(primitives.release());
	ASSERT_TRUE(scene->Configure(config.Root().Child("scene")));
	ASSERT_TRUE(scene->Build());

	BPTPathVertexPool pool;
	BPTSubpath subpathL(TransportDirection::LE);
	BPTSubpath subpathE(TransportDirection::EL);

	std::unique_ptr<ConfigurableSampler> sampler(ComponentFactory::Create<ConfigurableSampler>("random"));
	ASSERT_TRUE(sampler->Configure(ConfigNode(), *assets));
	sampler->SetSeed(1);

	const int Samples = 1<<10;
	for (int sample = 0; sample < Samples; sample++)
	{
		pool.Release();
		subpathL.Clear();
		subpathE.Clear();
		subpathL.Sample(*scene, *sampler, pool, 3, -1);
		subpathE.Sample(*scene, *sampler, pool, 3, -1);

		const int nL = subpathL.NumVertices();
		const int nE = subpathE.NumVertices();
		for (int s = 0; s <= nL; s++)
		{
			for (int t = 0; t <= nE; t++)
			{
				// # of vertices must be no less than 2
				const int n = s + t;
				if (n < 2)
				{
					continue;
				}
				
				// Between termination vertices geometry term must be positive
				// Otherwise, EvaluateFullpathPDFRatio is invalid due to offsetting of geometry terms.
				Math::Float connGeom(-1);
				if (s > 0 && t > 0)
				{
					connGeom = RenderUtils::GeneralizedGeometryTermWithVisibility(*scene, subpathL.Vertex(s-1)->geom, subpathE.Vertex(t-1)->geom);
					if (Math::Abs(connGeom) < Math::Constants::Eps())
					{
						continue;
					}
				}

				BPTFullPath fullpath(s, t, subpathL, subpathE);
				auto ps = fullpath.EvaluateFullpathPDF(s);
				if (Math::Abs(ps) < Math::Constants::Eps())
				{
					// EvaluateFullpathPDFRatio is invalid if p_s is zero
					continue;
				}

				for (int i = 0; i < n; i++)
				{
					auto pi		= fullpath.EvaluateFullpathPDF(i);
					auto piNext	= fullpath.EvaluateFullpathPDF(i+1);
					auto ratio	= fullpath.EvaluateFullpathPDFRatio(i);

					bool piIsZero		= Math::Abs(pi) < Math::Constants::Eps();
					bool piNextIsZero	= Math::Abs(piNext) < Math::Constants::Eps();

					// We note that we have only to check the case with p_i and p_{i+1} are both non-zero
					// because in actual weight calculation (cf. bpt.mis.power.cpp)
					// calculation of the ratio is aborted immediately after p_i or p_{i+1} is found to be non-zero.
					bool cond = false;
					if (piIsZero && piNextIsZero)
					{
						continue;
					}
					else if (piIsZero)
					{
						auto result = ExpectNear(Math::Float(0), ratio);
						EXPECT_TRUE(result);
						cond = result;
					}
					else if (piNextIsZero)
					{
						auto result = ExpectNear(Math::Float(0), ratio);
						EXPECT_TRUE(result);
						cond = result;
					}
					else
					{
						auto result = ExpectNearRelative(ratio, piNext / pi, Math::Constants::EpsLarge());
						EXPECT_TRUE(result);
						cond = result;
					}

					if (!cond)
					{
						LM_LOG_DEBUG("Evaluating i = " + std::to_string(i));
						LM_LOG_DEBUG("connGeom = " + std::to_string(connGeom));
						LM_LOG_DEBUG("ps       = " + std::to_string(ps));
						LM_LOG_DEBUG("pi       = " + std::to_string(pi));
						LM_LOG_DEBUG("piNext   = " + std::to_string(piNext));
						LM_LOG_DEBUG("ratio    = " + std::to_string(ratio));
						fullpath.DebugPrint();
					}
				}
			}
		}
	}
}
Ejemplo n.º 6
0
	const k3d::selection::set operator()(k3d::inode* const Node, const k3d::mesh& Mesh, const k3d::selection::set& CurrentSelection, const k3d::selection::records& InteractiveSelection) const
	{
		k3d::selection::set results = CurrentSelection;

		// Extract the set of edges to be selected ...
		mesh::indices_t edges;
		mesh::indices_t edge_primitives;
		for(k3d::selection::records::const_iterator record = InteractiveSelection.begin(); record != InteractiveSelection.end(); ++record)
		{
			if(k3d::selection::get_node(*record) != Node)
				continue;

			for(k3d::selection::record::tokens_t::const_iterator primitive_token = record->tokens.begin(); primitive_token != record->tokens.end(); ++primitive_token)
			{
				if(primitive_token->type != k3d::selection::PRIMITIVE)
					continue;

				for(k3d::selection::record::tokens_t::const_iterator edge_token = primitive_token + 1; edge_token != record->tokens.end(); ++edge_token)
				{
					if(edge_token->type != k3d::selection::EDGE)
						continue;

					edges.push_back(edge_token->id);
					edge_primitives.push_back(primitive_token->id);

					break;	
				}

				break;
			}
		}

		// Get the set of unique primitives ...
		std::set<uint_t> primitives(edge_primitives.begin(), edge_primitives.end());

		// Optionally select adjacent edges ...
		if(select_adjacent)
		{
			const uint_t edge_begin = 0;
			const uint_t edge_end = edge_begin + edges.size();

			for(std::set<uint_t>::const_iterator primitive = primitives.begin(); primitive != primitives.end(); ++primitive)
			{
				if(Mesh.primitives.size() <= *primitive)
					continue;

				boost::scoped_ptr<polyhedron::const_primitive> polyhedron(polyhedron::validate(Mesh, *Mesh.primitives[*primitive]));
				if(!polyhedron)
					continue;

				mesh::bools_t boundary_edges;
				mesh::indices_t adjacent_edges;
				polyhedron::create_edge_adjacency_lookup(polyhedron->vertex_points, polyhedron->clockwise_edges, boundary_edges, adjacent_edges);

				std::set<uint_t> primitive_edges;
				for(uint_t edge = edge_begin; edge != edge_end; ++edge)
				{
					if(edge_primitives[edge] != *primitive)
						continue;
					primitive_edges.insert(edges[edge]);
				}

				for(std::set<uint_t>::const_iterator edge = primitive_edges.begin(); edge != primitive_edges.end(); ++edge)
				{
					if(boundary_edges[*edge])
						continue;
					if(primitive_edges.count(adjacent_edges[*edge]))
						continue;

					edges.push_back(adjacent_edges[*edge]);
					edge_primitives.push_back(*primitive);
				}
			}
		}

		// Add all our edges to the output selection ...
		if(edges.size())
		{
			const uint_t edge_begin = 0;
			const uint_t edge_end = edge_begin + edges.size();

			boost::scoped_ptr<geometry::primitive_selection::storage> primitive_selection(geometry::primitive_selection::create(results));

			for(std::set<uint_t>::const_iterator primitive = primitives.begin(); primitive != primitives.end(); ++primitive)
			{
				primitive_selection->primitive_begin.push_back(*primitive);
				primitive_selection->primitive_end.push_back(*primitive + 1);
				primitive_selection->primitive_selection_type.push_back(k3d::selection::EDGE);
				primitive_selection->primitive_first_range.push_back(primitive_selection->index_begin.size());
				primitive_selection->primitive_range_count.push_back(0);
				for(uint_t edge = edge_begin; edge != edge_end; ++edge)
				{
					if(edge_primitives[edge] != *primitive)
						continue;
					primitive_selection->primitive_range_count.back() += 1;
					primitive_selection->index_begin.push_back(edges[edge]);
					primitive_selection->index_end.push_back(edges[edge] + 1);
					primitive_selection->weight.push_back(weight);
				}
			}
		}

		return results;
	}