Exemplo n.º 1
0
	TriMesh<FloatType> Shapes<FloatType>::torus(const vec3<FloatType> &center, FloatType majorRadius, FloatType minorRadius, UINT stacks, UINT slices, const std::function<vec4<FloatType>(unsigned int)> &stackIndexToColor)
	{
		std::vector<typename TriMesh<FloatType>::Vertex> vertices(slices * stacks);
		std::vector<UINT> indices(stacks * slices * 6);

		UINT vIndex = 0;
		// initial theta faces y front
		FloatType baseTheta = ml::math::PIf / 2.0f;
		for (UINT i = 0; i < stacks; i++)
		{
			FloatType theta = FloatType(i) * 2.0f * ml::math::PIf / FloatType(stacks) + baseTheta;
			auto color = stackIndexToColor(i);
			FloatType sinT = sinf(theta);
			FloatType cosT = cosf(theta);
			ml::vec3<FloatType> t0(cosT * majorRadius, sinT * majorRadius, 0.0f);
			for (UINT i2 = 0; i2 < slices; i2++)
			{
				auto& vtx = vertices[vIndex++];

				FloatType phi = FloatType(i2) * 2.0f * ml::math::PIf / FloatType(slices);
				FloatType sinP = sinf(phi);
				vtx.position = ml::vec3<FloatType>(minorRadius * cosT * sinP, minorRadius * sinT * sinP, minorRadius * cosf(phi)) + t0;
				vtx.color = color;
			}
		}

		UINT iIndex = 0;
		for (UINT i = 0; i < stacks; i++)
		{
			UINT ip1 = (i + 1) % stacks;
			for (UINT i2 = 0; i2 < slices; i2++)
			{
				UINT i2p1 = (i2 + 1) % slices;

				indices[iIndex++] = ip1 * slices + i2;
				indices[iIndex++] = i * slices + i2;
				indices[iIndex++] = i * slices + i2p1;

				indices[iIndex++] = ip1 * slices + i2;
				indices[iIndex++] = i * slices + i2p1;
				indices[iIndex++] = ip1 * slices + i2p1;
			}
		}

		return TriMesh<FloatType>(vertices, indices, true);
	}
Exemplo n.º 2
0
void VRSnappingEngine::setPreset(PRESET preset) {
    clear();

    Line t0(Pnt3f(0,0,0), Vec3f(0,0,0));
    Line o0(Pnt3f(0,0,-1), Vec3f(0,1,0));

    switch(preset) {
        case SIMPLE_ALIGNMENT:
            addRule(POINT, POINT, t0, o0, 1, 1, 0);
            addRule(LINE, POINT, Line(Pnt3f(), Vec3f(1,0,0)), o0, 1, 1, 0);
            addRule(LINE, POINT, Line(Pnt3f(), Vec3f(0,1,0)), o0, 1, 1, 0);
            addRule(LINE, POINT, Line(Pnt3f(), Vec3f(0,0,1)), o0, 1, 1, 0);
            break;
        case SNAP_BACK:
            addRule(POINT, POINT, t0, o0, 1, 1, 0);
            break;
    }
}
Exemplo n.º 3
0
void TestResolution() {
    static double target_value = 0.314159265358979323846264338327950288419;
    static double step_value = 0.00027182818284590452353602874713526624977572;
    static int range_value = 100;
    double avg_diff = 0.0;
    double max_diff = 0.0;
    for( int i = -range_value; i <= range_value; ++i ) {
        double my_time = target_value + step_value * i;
        tbb::tick_count::interval_t t0(my_time);
        double interval_time = t0.seconds();
        avg_diff += (my_time - interval_time);
        if ( max_diff < my_time-interval_time) max_diff = my_time-interval_time;
        // time always truncates
        ASSERT(interval_time >= 0 && my_time - interval_time < tbb::tick_count::resolution(), "tick_count resolution out of range");
    }
    avg_diff = (avg_diff/(2*range_value+1))/tbb::tick_count::resolution();
    max_diff /= tbb::tick_count::resolution();
    REMARK("avg_diff = %g ticks, max_diff = %g ticks\n", avg_diff, max_diff);
}
dgInt32 FastRayTest::BoxTestSimd (const dgVector& minBox, const dgVector& maxBox) const
{
	simd_128 boxP0 ((simd_128&)minBox);
	simd_128 boxP1 ((simd_128&)maxBox);

	simd_128 tt0 (((simd_128&)m_p0 <= boxP0) | ((simd_128&)m_p0 >= boxP1) & (simd_128&)m_isParallel);
	if (tt0.GetSignMask() & 0x07) {
		return 0;
	}
	tt0 = (boxP0 - (simd_128&)m_p0) * (simd_128&)m_dpInv;
	simd_128 tt1 ((boxP1 - (simd_128&)m_p0) * (simd_128&)m_dpInv);
	simd_128 t0 (((simd_128&)m_minT).GetMax(tt0.GetMin(tt1)));
	simd_128 t1 (((simd_128&)m_maxT).GetMin(tt0.GetMax(tt1)));
	t0 = t0.GetMax(t0.ShiftTripleRight());
	t1 = t1.GetMin(t1.ShiftTripleRight());
	t0 = t0.GetMax(t0.ShiftTripleRight());
	t1 = t1.GetMin(t1.ShiftTripleRight());
	return ((t0 < t1).GetSignMask() & 1);
}
dgBigVector LineTriangleIntersection (const dgBigVector& p0, const dgBigVector& p1, const dgBigVector& A, const dgBigVector& B, const dgBigVector& C)
{
	dgHugeVector ph0 (p0);
	dgHugeVector ph1 (p1);
	dgHugeVector Ah (A);
	dgHugeVector Bh (B);
	dgHugeVector Ch (C);

	dgHugeVector p1p0 (ph1 - ph0);
	dgHugeVector Ap0 (Ah - ph0);
	dgHugeVector Bp0 (Bh - ph0);
	dgHugeVector Cp0 (Ch - ph0);

	dgGoogol t0 ((Bp0 * Cp0) % p1p0);
	dgFloat64 val0 = t0.GetAproximateValue();	
	if (val0 < dgFloat64 (0.0f)) {
		return dgBigVector (dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (-1.0f));
	}

	dgGoogol t1 ((Cp0 * Ap0) % p1p0);
	dgFloat64 val1 = t1.GetAproximateValue();	
	if (val1 < dgFloat64 (0.0f)) {
		return dgBigVector (dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (-1.0f));
	}

	dgGoogol t2 ((Ap0 * Bp0) % p1p0);
	dgFloat64 val2 = t2.GetAproximateValue();	
	if (val2 < dgFloat64 (0.0f)) {
		return dgBigVector (dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (-1.0f));
	}

	dgGoogol sum = t0 + t1 + t2;
	dgFloat64 den = sum.GetAproximateValue();

#ifdef _DEBUG
	dgBigVector testpoint (A.Scale (val0 / den) + B.Scale (val1 / den) + C.Scale(val2 / den));
	dgFloat64 volume = ((B - A) * (C - A)) % (testpoint - A);
	_ASSERTE (fabs (volume) < dgFloat64 (1.0e-12f));
#endif


	return dgBigVector (val0 / den, val1 / den, val2 / den, dgFloat32 (0.0f));
}
Exemplo n.º 6
0
int main(int argc, char const* argv[]) {
    // The order of creation is important; it makes it more likely that
    // A will appear first in the list of vertices of the lock graph,
    // making the algorithm find a cycle A->B->C->A instead of some
    // other permutation of it. If the algorithm finds another permutation
    // of the cycle, this test is useless.
    d2mock::mutex A;
    d2mock::mutex B;
    d2mock::mutex C;

    d2mock::thread t0([&] {
        A.lock();
            B.lock();
            B.unlock();
        A.unlock();
    });

    d2mock::thread t1([&] {
        B.lock();
            C.lock();
            C.unlock();
        B.unlock();
    });

    d2mock::thread t2([&] {
        C.lock();
            A.lock();
            A.unlock();
        C.unlock();
    });

    auto test_main = [&] {
        t0.start();
            t2.start();
            t2.join();

            t1.start();
            t1.join();
        t0.join();
    };

    return d2mock::check_scenario(test_main, argc, argv, {/* none */});
}
int Intersect(const TSegment2<NumericType> &S1, const TSegment2<NumericType> &S2, TPt2<NumericType> *x){
	typedef TVec2<NumericType> vec_t;
	vec_t v1(S1[1]-S1[0]), v2(S2[1]-S2[0]);
	vec_t v3(S2[0]-S1[0]);
	NumericType denom(vec_t::Cross(v1,v2));
	if(0 == denom){
		// parallel segments
		TLine2<NumericType> L1(S1.Line());
		if(L1.SideOf(S2[0]) == 0){
			// collinear segments, find endpoints of overlap
			NumericType t0(L1.Projection(S2[0]));
			NumericType t1(L1.Projection(S2[1]));
			if(t0 > t1){ std::swap(t0,t1); }
			// Returns midpoint of overlapping segment if possible
			if(NumericType(0) <= t0 && t0 <= NumericType(1)){
				if(NumericType(0) <= t1 && t1 <= NumericType(1)){
					if(NULL != x){
						x[0] = L1[(t0+t1)/NumericType(2)];
					}
				}else{
					if(NULL != x){
						x[0] = L1[(t0+NumericType(1))/NumericType(2)];
					}
				}
				return -1;
			}else if(NumericType(0) <= t1 && t1 <= NumericType(1)){
				if(NULL != x){
					x[0] = L1[t1/NumericType(2)];
				}
				return -1;
			}else{ // collinear but no intersections
				return 0;
			}
		}else{
			return 0;
		}
	}else{
		NumericType t(vec_t::Cross(v3,v2)/denom);
		if(NULL != x){ x[0] = S1.Line()[t]; }
		return 1;
	}
}
Exemplo n.º 8
0
CImage *CImageLABtoXYZ(CImage *cimg)
{
  CImage *ncimg=NULL;
  int p,n,i;


  ncimg = CreateCImage(cimg->C[0]->ncols,cimg->C[0]->nrows);
  n    = ncimg->C[0]->ncols*ncimg->C[0]->nrows;

  for (p=0; p < n; p++){

    i = triplet(cimg->C[0]->val[p],cimg->C[1]->val[p],cimg->C[2]->val[p]);
    i = LAB2XYZ(i);
    ncimg->C[0]->val[p]=t0(i);
    ncimg->C[1]->val[p]=t1(i);
    ncimg->C[2]->val[p]=t2(i);
  }

  return(ncimg);
}
Exemplo n.º 9
0
dirac_sequence generate_dirac_sequence(double speed_of_sound,
                                       double room_volume,
                                       double sample_rate,
                                       double max_time) {
    const auto constant_mean_occurrence =
            constant_mean_event_occurrence(speed_of_sound, room_volume);

    std::default_random_engine engine{std::random_device{}()};

    util::aligned::vector<float> ret(std::ceil(max_time * sample_rate), 0);
    for (auto t = t0(constant_mean_occurrence); t < max_time;
         t += interval_size(
                 engine, mean_event_occurrence(constant_mean_occurrence, t))) {
        const auto sample_index = t * sample_rate;
        const size_t twice = 2 * sample_index;
        const bool negative = (twice % 2) != 0;
        ret[sample_index] = negative ? -1 : 1;
    }
    return {ret, sample_rate};
}
Exemplo n.º 10
0
DEF_TEST(TypefaceCache, reporter) {
    sk_sp<SkTypeface> t1(SkEmptyTypeface::Create());
    {
        SkTypefaceCache cache;
        REPORTER_ASSERT(reporter, count(reporter, cache) == 0);
        {
            sk_sp<SkTypeface> t0(SkEmptyTypeface::Create());
            cache.add(t0.get());
            REPORTER_ASSERT(reporter, count(reporter, cache) == 1);
            cache.add(t1.get());
            REPORTER_ASSERT(reporter, count(reporter, cache) == 2);
            cache.purgeAll();
            REPORTER_ASSERT(reporter, count(reporter, cache) == 2);
        }
        REPORTER_ASSERT(reporter, count(reporter, cache) == 2);
        cache.purgeAll();
        REPORTER_ASSERT(reporter, count(reporter, cache) == 1);
    }
    REPORTER_ASSERT(reporter, t1->unique());
}
Exemplo n.º 11
0
void AddCylinder(Geometry*g,float h,float r, int sides)
{
    Geometry tmp;
    float ang=(float)(PI*2.0/sides);
    float sina=sin(ang),cosa=cos(ang);
    int i;
    vec3 t1(r,0,0),t0(r,0,0),hh(0,h,0),hh0(0,0,0);
    for(i=0; i<sides; i++)
    {
        t1.RotateOij(sina,cosa,0,2);
        AddQuad(&tmp,t0,t1,t1+hh,t0+hh);
        tmp.AddTriangle(t0,t1,hh0);
        tmp.AddTriangle(t1+hh,t0+hh,hh);
        t0=t1;
    }

    tmp.SetNormOutOf(vec3(0,h/2,0));

    g->Add(tmp);

}
Exemplo n.º 12
0
// Adapted from SV-COMP'13 benchmark:
//  https://svn.sosy-lab.org/software/sv-benchmarks/trunk/c/pthread/fib_bench_longer_false-unreach-label.c
TEST(CrvFunctionalTest, SatFib6)
{
  constexpr unsigned N = 6;

  crv::tracer().reset();
  crv::Encoder encoder;

  crv::External<int> i = 1, j = 1;
  crv::Thread t0(fib_t0, N, i, j);
  crv::Thread t1(fib_t1, N, i, j);

  crv::tracer().add_error(377 <= i || 377 <= j);

  t0.join();
  t1.join();

  EXPECT_TRUE(crv::tracer().assertions().empty());
  EXPECT_FALSE(crv::tracer().errors().empty());
  EXPECT_TRUE(smt::sat == encoder.check(crv::tracer()));
  EXPECT_FALSE(crv::tracer().flip());
}
Exemplo n.º 13
0
void AST_If_Statement::print(const int tabStop, std::ostringstream &stream) const
{
    std::string t0(tabStop, 32);
    stream << t0 << "if (";
    m_BoolExpression->print(0, stream);
    std::string t1(tabStop+1, 32);
    stream
            << ") then \n"
            << t0 << "begin \n";
    AST_BaseStatement::printList(tabStop +1, stream, m_IfTrueStatements);
    stream
            << t0 << "end";
    if(m_GotElse)
    {
        stream << t0 << "\n" <<  t0 <<"else \n";
        stream << t0 << "begin \n";
        AST_BaseStatement::printList(tabStop +1, stream, m_IfFalseStatements);
        stream
                << t0 << "end";
    }
}
Exemplo n.º 14
0
int main(){
    TreeNode t0(15);
    TreeNode t1(10);
    TreeNode t2(20);
    TreeNode t3(8);
    TreeNode t4(12);
    TreeNode t5(16);
    TreeNode t6(25);
    TreeNode t7(13);
    TreeNode t8(17);
    t0.left = &t1;
    t0.right = &t2;
    t1.left = &t3;
    t1.right = &t4;
    t2.left = &t5;
    t2.right = &t6;
    t4.right = &t7;
    t5.right = &t8;
    cout<<lca(&t0,&t3,&t7)->val<<endl;
    return 0;
}
Exemplo n.º 15
0
/*----------------------------------------------------------------------
|   TestSharedVariables
+---------------------------------------------------------------------*/
static void
TestSharedVariables()
{
	NPT_SharedVariable shared;
	SharedVariableThread t0(1, 2, shared, 0);
	SharedVariableThread t1(2, 1, shared, 0.001f);

	t0.Start();
	t1.Start();

	shared.SetValue(1);
	NPT_Result result = t0.Wait(10000);
	t0.m_Stop = true;
	t1.m_Stop = true;
	t1.Wait();

	NPT_Console::OutputF("T0 transitions=%d, result: %d\n", t0.m_Transitions, t0.m_Result);
	NPT_Console::OutputF("T1 transitions=%d, result: %d\n", t1.m_Transitions, t1.m_Result);

	CHECK(t0.m_Result == NPT_SUCCESS);
	CHECK(t1.m_Result == NPT_SUCCESS);
}
Exemplo n.º 16
0
void fiber_example()
{
	iocp::service svr;
	fiber::scheduler *data = fiber::scheduler::convert_thread(0);
	//iocp::fiber_socket socket(svr);
	//socket.invoke(request_proc, &socket);
	iocp::fiber_acceptor http_acceptor(svr);
	http_acceptor.invoke(acceptot_proc, &http_acceptor);
	iocp::fiber_acceptor https_acceptor(svr);
	https_acceptor.invoke(ssl_acceptot_proc, &https_acceptor);

	iocp::thread t0(fiber_thread_proc, &svr);

	printf("started\n");
	iocp::error_code ec;
	size_t result;
	result = svr.run(ec);
	t0.join();

	std::cout << "finished " << result << " operations" << std::endl;
	std::cout << ec.to_string() << std::endl;
}
Exemplo n.º 17
0
int main()
{
	std::shared_ptr<Int42Producer> int42Producer(new Int42Producer());
	std::shared_ptr<MultiplyIntBy2> consumerProducer(new MultiplyIntBy2(int42Producer, 10));
	std::shared_ptr<IntOutput> intOutput(new IntOutput(consumerProducer));

	std::thread t0(&Int42Producer::start, int42Producer);
	std::thread t1(&MultiplyIntBy2::start, consumerProducer);
	std::thread t2(&IntOutput::start, intOutput);
	
	std::this_thread::sleep_for(std::chrono::seconds(10));

	intOutput->shutdown();
	consumerProducer->shutdown();
	int42Producer->shutdown();

	t0.join();
	t1.join();
	t2.join();

	return 0;
}
Exemplo n.º 18
0
int main() {
    Time t0(0, 0, 0);
    Time t1(0, 12, 12);
    Time t2(12, 0, 0);
    Time t3(14,4, 5);
    // Time t1;
    t0.PrintAmPm();
    t1.PrintAmPm();
    t2.PrintAmPm();
    t3.PrintAmPm();
    std::vector<Time> times;
    times.push_back(t3);
    times.push_back(t2);
    times.push_back(t1);
    times.push_back(t0);
    sort(times.begin(), times.end(), isEarlierThan);

    for (unsigned int i = 0; i < times.size(); i++) {
        times[i].PrintAmPm();
    }
    return 0;
}
Exemplo n.º 19
0
void Model::addPlane(const glm::vec3 &a, const glm::vec3 &b, const glm::vec3 &c, const glm::vec4 &texRect) {
    glm::vec3 normal = normalize(cross(c - b, a - b));
    glm::vec3 d = a + c - b;

    glm::vec2 t0(texRect.x, texRect.y);
    glm::vec2 t1(texRect.x + texRect.z, texRect.y + texRect.w);

    switch (mPrimitive) {
        case GLTriangles: {
            reserveIndices(6);
            size_t n = mVertices.size();
            addQuad(n+0, n+1, n+2, n+3);

            reserveVertices(4);
            addVertex(Vertex(glm::vec2(t1.x,t0.y), normal, c));
            addVertex(Vertex(glm::vec2(t1.x,t1.y), normal, d));
            addVertex(Vertex(glm::vec2(t0.x,t1.y), normal, a));
            addVertex(Vertex(glm::vec2(t0.x,t0.y), normal, b));
            break;
        }
    }
}
Exemplo n.º 20
0
int main(int argc, char const* argv[]) {
    d2mock::mutex G;

    d2mock::thread t1([&] {
        G.lock();
        G.unlock();
    });

    d2mock::thread t0([&] {
        t1.start();
        // if t0 acquires G before t1 does, t1 can never be joined
        G.lock();
        t1.join();
        G.unlock();
    });

    auto test_main = [&] {
        t0.start();
        t0.join();
    };

    // Right now, we have no way of encoding these kinds of deadlocks,
    // and we're obviously not detecting them too. For now, we'll always
    // make the test fail.
#if 1
    (void)test_main;
    return EXIT_FAILURE;
#else
    return d2mock::check_scenario(test_main, argc, argv, {
                {
                    // t0 holds G, and waits for t1 to join
                    {t0, G, join(t1)},
                    // t1 waits for G, and will never be joined
                    {t1, G}
                }
            });
#endif
}
Exemplo n.º 21
0
void Model::addBox(const glm::vec3 &size, const glm::vec3 &center, const glm::vec4 &texRect) {
    glm::vec3 mx = center + size;
    glm::vec3 mn = center - size;

    glm::vec2 t0(texRect.x, texRect.y);
    glm::vec2 t1(texRect.x + texRect.z, texRect.y + texRect.w);

    glm::vec3 a(mn.x, mn.y, mn.z);
    glm::vec3 b(mx.x, mn.y, mn.z);
    glm::vec3 c(mn.x, mx.y, mn.z);
    glm::vec3 d(mx.x, mx.y, mn.z);
    glm::vec3 e(mn.x, mn.y, mx.z);
    glm::vec3 f(mx.x, mn.y, mx.z);
    glm::vec3 g(mn.x, mx.y, mx.z);
    glm::vec3 h(mx.x, mx.y, mx.z);

    addPlane(h, f, b, texRect);
    addPlane(c, a, e, texRect);
    addPlane(c, g, h, texRect);
    addPlane(e, a, b, texRect);
    addPlane(g, e, f, texRect);
    addPlane(d, b, a, texRect);
}
Exemplo n.º 22
0
TEST(CrvFunctionalTest, UnsatStack)
{
  constexpr unsigned N = 5;

  crv::tracer().reset();
  crv::Encoder encoder;

  crv::Mutex mutex;
  crv::External<unsigned int> top(0U);

  bool error = false;
  do
  {
    crv::Thread t0(unsat_stack_t0, N, mutex, top);
    crv::Thread t1(unsat_stack_t1, N, mutex, top);

    if (!crv::tracer().errors().empty() &&
        smt::sat == encoder.check(crv::tracer()))
      error = true;
  }
  while (crv::tracer().flip());
  EXPECT_FALSE(error);
}
//_____________________________________________________________________________
bool THaSpectrometerDetector::CalcTrackIntercept(THaTrack* theTrack, 
					 Double_t& t, Double_t& xcross, 
					 Double_t& ycross)
{
  // projects a given track on to the plane of the detector
  // xcross and ycross are the x and y coords of this intersection
  // t is the distance from the origin of the track to the given plane.
  // 
  // If a hit is NOT found, then t, xcross, and ycross are unchanged.
  TVector3 t0( theTrack->GetX(), theTrack->GetY(), 0.0 );
  Double_t norm = TMath::Sqrt(1.0 + theTrack->GetTheta()*theTrack->GetTheta() +
			      theTrack->GetPhi()*theTrack->GetPhi());
  TVector3 t_hat( theTrack->GetTheta()/norm, theTrack->GetPhi()/norm, 1.0/norm );

  TVector3 v;
  if( !IntersectPlaneWithRay( fXax, fYax, fOrigin, t0, t_hat, t, v ))
    return false;
  v -= fOrigin;
  xcross = v.Dot(fXax);
  ycross = v.Dot(fYax);

  return true;
}
void DialogTimeStampGenerator2::on_pushButton_clicked()
{
	static TB2PC_PACKET p;
	static ALIVE_PACKET ap;

	p.magicNumber1 = MAGIC_NUMBER1;
	p.magicNumber2 = MAGIC_NUMBER2;

	p.packetVersion = ui->lineEdit_packetVersion->text().toInt();
	p.batteryVoltageTB = ui->lineEdit_batteryVoltageTB->text().toInt();
	p.triggerStationID = ui->comboBox_triggerStationID->itemData(ui->comboBox_triggerStationID->currentIndex()).toInt();
	p.binRssiTS = ui->lineEdit_binRssiTS->text().toInt();

	QTime t0(0,0,0);
	ap.triggerTimeBB = t0.msecsTo(ui->timeEdit_triggerTimeBB->time())*10;
	ap.triggerTimeTS_L = t0.msecsTo(ui->timeEdit_triggerTimeTS_L->time())*10;
	ap.triggerTimeTS_R = t0.msecsTo(ui->timeEdit_triggerTimeTS_R->time())*10;
	ap.batteryVoltageTS = ui->lineEdit_batteryVoltageTS->text().toInt();
	ap.batteryVoltageBB = ui->lineEdit_batteryVoltageBB->text().toInt();
	ap.boatBoxID = ui->comboBox_boatBoxID->itemData(ui->comboBox_boatBoxID->currentIndex()).toInt();
	ap.binRssiBB = ui->lineEdit_binRssiBB->text().toInt();
	ap.stationTriggeredAt = ui->comboBox_stationTriggeredAt->itemData(ui->comboBox_stationTriggeredAt->currentIndex()).toInt();

	p.tsPacket = ap;

	p.baseTime_100us = t0.msecsTo(ui->timeEdit_baseTime->time())*10;

	p.crc = CRC8_run((uint8_t*)(&p), sizeof(p)-1);

	//printPacket(p);

	QByteArray datagram;
	datagram.setRawData((char*)(&p), sizeof(p));

	QUdpSocket* udpSocket = new QUdpSocket(this);
	udpSocket->writeDatagram(datagram.data(), datagram.size(), QHostAddress::Broadcast, UDP_LISTEN_PORT);
}
Exemplo n.º 25
0
dgBigVector LineTriangleIntersection (const dgBigVector& p0, const dgBigVector& p1, const dgBigVector& A, const dgBigVector& B, const dgBigVector& C)
{
	dgHugeVector ph0 (p0);
	dgHugeVector ph1 (p1);
	dgHugeVector Ah (A);
	dgHugeVector Bh (B);
	dgHugeVector Ch (C);

	dgHugeVector p1p0 (ph1 - ph0);
	dgHugeVector Ap0 (Ah - ph0);
	dgHugeVector Bp0 (Bh - ph0);
	dgHugeVector Cp0 (Ch - ph0);

	dgGoogol t0 ((Bp0 * Cp0) % p1p0);
	double val0 = t0.GetAproximateValue();	
	if (val0 < double (0.0f)) {
		return dgBigVector (float (0.0f), float (0.0f), float (0.0f), float (-1.0f));
	}

	dgGoogol t1 ((Cp0 * Ap0) % p1p0);
	double val1 = t1.GetAproximateValue();	
	if (val1 < double (0.0f)) {
		return dgBigVector (float (0.0f), float (0.0f), float (0.0f), float (-1.0f));
	}

	dgGoogol t2 ((Ap0 * Bp0) % p1p0);
	double val2 = t2.GetAproximateValue();	
	if (val2 < double (0.0f)) {
		return dgBigVector (float (0.0f), float (0.0f), float (0.0f), float (-1.0f));
	}

	dgGoogol sum = t0 + t1 + t2;
	double den = sum.GetAproximateValue();

	return dgBigVector (val0 / den, val1 / den, val2 / den, float (0.0f));
}
Exemplo n.º 26
0
	VML::Vector3 Vec3CatmullRom::Interpolate(float t) const
	{
		assert(IsReady());

		processTime(t);
		size_t segm = findSegment(t); 
		size_t n_ctrl = mKeyframes.size();

		const VML::Vector3& p0 = mKeyframes[segm].data;
		const VML::Vector3& p1 = mKeyframes[segm + 1].data;
		float time0 = mKeyframes[segm].time;
		float time1 = mKeyframes[segm + 1].time;

		VML::Vector3 t0(0);
		VML::Vector3 t1(0);

		if(segm > 0 && segm < n_ctrl - 2)
		{
			t0 = (p1 - mKeyframes[segm - 1].data) * 0.5f;
			t1 = (mKeyframes[segm + 2].data - p0) * 0.5f;
		}
		else if(segm == 0 && n_ctrl > 2)
		{
			t0 = (p1 + p1 - mKeyframes[segm + 2].data - p0) * 0.5f;
			t1 = (mKeyframes[segm + 2].data - p0) * 0.5f;
		}
		else if (segm == n_ctrl - 2 && n_ctrl > 2)
		{
			t0 = (p1 - mKeyframes[segm - 1].data) * 0.5f;
			t1 = - (p0 + p0 - mKeyframes[segm - 1].data - p1) * 0.5f;
		}

		float u = (t - time0) / (time1 - time0), u2 = u*u, u3 = u2*u;
		VML::Vector3 pos = p0*(2.0f*u3 - 3.0f*u2 + 1.0f) + p1*(-2.0f*u3 + 3.0f*u2) + t0*(u3 - 2.0f*u2 + u) + t1*(u3 - u2);
		return pos;
	}
Exemplo n.º 27
0
int main()
{
  {
    boost::thread t0( (G()));
    BOOST_TEST(t0.joinable());
    t0.try_join_until(boost::chrono::steady_clock::now()+boost::chrono::milliseconds(50));
    BOOST_TEST(!t0.joinable());
  }
  {
    boost::thread t0( (th_100_ms));
    BOOST_TEST(!t0.try_join_until(boost::chrono::steady_clock::now()+boost::chrono::milliseconds(50)));
    t0.join();
  }

  {
    boost::unique_lock<boost::mutex> lk(resource_deadlock_would_occur_mtx);
    boost::thread t0( resource_deadlock_would_occur_tester );
    resource_deadlock_would_occur_th = &t0;
    BOOST_TEST(t0.joinable());
    lk.unlock();
    boost::this_thread::sleep_for(boost::chrono::milliseconds(100));
    boost::unique_lock<boost::mutex> lk2(resource_deadlock_would_occur_mtx);
    t0.join();
    BOOST_TEST(!t0.joinable());
  }

  {
    boost::thread t0( (G()));
    t0.detach();
    try
    {
      t0.try_join_until(boost::chrono::steady_clock::now()+boost::chrono::milliseconds(50));
      BOOST_TEST(false);
    }
    catch (boost::system::system_error& e)
    {
      BOOST_TEST(e.code().value() == boost::system::errc::invalid_argument);
    }
  }
  {
    boost::thread t0( (G()));
    BOOST_TEST(t0.joinable());
    t0.join();
    try
    {
      t0.try_join_until(boost::chrono::steady_clock::now()+boost::chrono::milliseconds(50));
      BOOST_TEST(false);
    }
    catch (boost::system::system_error& e)
    {
      BOOST_TEST(e.code().value() == boost::system::errc::invalid_argument);
    }

  }
  {
    boost::thread t0( (G()));
    BOOST_TEST(t0.joinable());
    t0.try_join_until(boost::chrono::steady_clock::now()+boost::chrono::milliseconds(50));
    try
    {
      t0.join();
      BOOST_TEST(false);
    }
    catch (boost::system::system_error& e)
    {
      BOOST_TEST(e.code().value() == boost::system::errc::invalid_argument);
    }

  }

  return boost::report_errors();
}
Exemplo n.º 28
0
inline void
internal::ApplyPackedReflectorsLLVF
( Conjugation conjugation, int offset, 
  const DistMatrix<Complex<R>,MC,MR  >& H,
  const DistMatrix<Complex<R>,MD,STAR>& t,
        DistMatrix<Complex<R>,MC,MR  >& A )
{
#ifndef RELEASE
    PushCallStack("internal::ApplyPackedReflectorsLLVF");
    if( H.Grid() != t.Grid() || t.Grid() != A.Grid() )
        throw std::logic_error
        ("{H,t,A} must be distributed over the same grid");
    if( offset > 0 )
        throw std::logic_error("Transforms cannot extend above matrix");
    if( offset < -H.Height() )
        throw std::logic_error("Transforms cannot extend below matrix");
    if( H.Height() != A.Height() )
        throw std::logic_error
        ("Height of transforms must equal height of target matrix");
    if( t.Height() != H.DiagonalLength( offset ) )
        throw std::logic_error("t must be the same length as H's offset diag.");
    if( !t.AlignedWithDiagonal( H, offset ) )
        throw std::logic_error("t must be aligned with H's 'offset' diagonal");
#endif
    typedef Complex<R> C;
    const Grid& g = H.Grid();

    // Matrix views    
    DistMatrix<C,MC,MR>
        HTL(g), HTR(g),  H00(g), H01(g), H02(g),  HPan(g), HPanCopy(g),
        HBL(g), HBR(g),  H10(g), H11(g), H12(g),
                         H20(g), H21(g), H22(g);
    DistMatrix<C,MC,MR>
        AT(g),  A0(g),
        AB(g),  A1(g),
                A2(g);
    DistMatrix<C,MD,STAR>
        tT(g),  t0(g),
        tB(g),  t1(g),
                t2(g);

    DistMatrix<C,VC,  STAR> HPan_VC_STAR(g);
    DistMatrix<C,MC,  STAR> HPan_MC_STAR(g);
    DistMatrix<C,STAR,STAR> t1_STAR_STAR(g);
    DistMatrix<C,STAR,STAR> SInv_STAR_STAR(g);
    DistMatrix<C,STAR,MR  > Z_STAR_MR(g);
    DistMatrix<C,STAR,VR  > Z_STAR_VR(g);

    LockedPartitionDownDiagonal
    ( H, HTL, HTR,
         HBL, HBR, 0 );
    LockedPartitionDown
    ( t, tT,
         tB, 0 );
    PartitionDown
    ( A, AT,
         AB, 0 );
    while( HTL.Height() < H.Height() && HTL.Width() < H.Width() )
    {
        LockedRepartitionDownDiagonal
        ( HTL, /**/ HTR,  H00, /**/ H01, H02,
         /*************/ /******************/
               /**/       H10, /**/ H11, H12,
          HBL, /**/ HBR,  H20, /**/ H21, H22 );

        int HPanHeight = H11.Height() + H21.Height();
        int HPanWidth = std::min( H11.Width(), std::max(HPanHeight+offset,0) );
        HPan.LockedView( H, H00.Height(), H00.Width(), HPanHeight, HPanWidth );

        LockedRepartitionDown
        ( tT,  t0,
         /**/ /**/
               t1,
          tB,  t2, HPanWidth );

        RepartitionDown
        ( AT,  A0,
         /**/ /**/
               A1,
          AB,  A2 );

        HPan_MC_STAR.AlignWith( AB );
        Z_STAR_MR.AlignWith( AB );
        Z_STAR_VR.AlignWith( AB );
        Z_STAR_MR.ResizeTo( HPan.Width(), AB.Width() );
        SInv_STAR_STAR.ResizeTo( HPan.Width(), HPan.Width() );
        Zero( SInv_STAR_STAR );
        //--------------------------------------------------------------------//
        HPanCopy = HPan;
        MakeTrapezoidal( LEFT, LOWER, offset, HPanCopy );
        SetDiagonalToOne( LEFT, offset, HPanCopy );

        HPan_VC_STAR = HPanCopy;
        Herk
        ( UPPER, ADJOINT, 
          (C)1, HPan_VC_STAR.LockedLocalMatrix(),
          (C)0, SInv_STAR_STAR.LocalMatrix() );     
        SInv_STAR_STAR.SumOverGrid();
        t1_STAR_STAR = t1;
        FixDiagonal( conjugation, t1_STAR_STAR, SInv_STAR_STAR );

        HPan_MC_STAR = HPanCopy;
        internal::LocalGemm
        ( ADJOINT, NORMAL, (C)1, HPan_MC_STAR, AB, (C)0, Z_STAR_MR );
        Z_STAR_VR.SumScatterFrom( Z_STAR_MR );
        
        internal::LocalTrsm
        ( LEFT, UPPER, ADJOINT, NON_UNIT, (C)1, SInv_STAR_STAR, Z_STAR_VR );

        Z_STAR_MR = Z_STAR_VR;
        internal::LocalGemm
        ( NORMAL, NORMAL, (C)-1, HPan_MC_STAR, Z_STAR_MR, (C)1, AB );
        //--------------------------------------------------------------------//
        HPan_MC_STAR.FreeAlignments();
        Z_STAR_MR.FreeAlignments();
        Z_STAR_VR.FreeAlignments();

        SlideLockedPartitionDownDiagonal
        ( HTL, /**/ HTR,  H00, H01, /**/ H02,
               /**/       H10, H11, /**/ H12,
         /*************/ /******************/
          HBL, /**/ HBR,  H20, H21, /**/ H22 );

        SlideLockedPartitionDown
        ( tT,  t0,
               t1,
         /**/ /**/
          tB,  t2 ); 

        SlidePartitionDown
        ( AT,  A0,
               A1,
         /**/ /**/
          AB,  A2 );
    }
#ifndef RELEASE
    PopCallStack();
#endif
}
Exemplo n.º 29
0
int main(int argc, char * const argv[])
{
        int opt_index, c;
        static struct option long_opts[] = {
                {"target", 1, 0, 0},
                {"dumpfile", 1, 0, 0},
                {0, 0, 0, 0}
        };

        if (argc < 4)
                usage(argv[0]);

        while ((c = getopt_long(argc, argv, "s:b:f:", long_opts, &opt_index)) != -1) {
                switch (c) {
                case 0: {
                        if (!optarg[0])
                                usage(argv[0]);

                        if (!strcmp(long_opts[opt_index].name, "target")) {
                                setenv(ENV_LUSTRE_MNTTGT, optarg, 1);
                        } else if (!strcmp(long_opts[opt_index].name, "dumpfile")) {
                                setenv(ENV_LUSTRE_DUMPFILE, optarg, 1);
                        } else
                                usage(argv[0]);
                        break;
                }
                case 's':
                        strcpy(mds_server, optarg);
                        break;
                case 'b':
                        strcpy(barrier_script, optarg);
                        break;
                case 'f':
                        strcpy(failover_script, optarg);
                        break;
                default:
                        usage(argv[0]);
                }
        }

        if (optind != argc)
                usage(argv[0]);
        if (!strlen(mds_server) || !strlen(barrier_script) ||
            !strlen(failover_script))
                usage(argv[0]);

        test_ssh();

        /* prepare remote command */
        sprintf(barrier_cmd, "ssh %s \"%s\"", mds_server, barrier_script);
        sprintf(failover_cmd, "ssh %s \"%s\"", mds_server, failover_script);

        setenv(ENV_LUSTRE_TIMEOUT, "5", 1);

        __liblustre_setup_();

        t0();
        t1();
        t2();
        t3();
        t4();

	printf("liblustre is about shutdown\n");
        __liblustre_cleanup_();

	printf("complete successfully\n");
	return 0;
}
Exemplo n.º 30
0
//Define vertices and triangles
void CTitanic::init(float aScale)
	{
	this->clearMesh();

	TVector3 v0(-4,2,2);
	this->iVertices.push_back(v0*aScale);

	TVector3 v1(-3,1,0);
	this->iVertices.push_back(v1*aScale);

	TVector3 v2(-3,-1,0);
	this->iVertices.push_back(v2*aScale);

	TVector3 v3(-4,-2,2);
	this->iVertices.push_back(v3*aScale);

	TVector3 v4(3,2,2);
	this->iVertices.push_back(v4*aScale);

	TVector3 v5(3,1,0);
	this->iVertices.push_back(v5*aScale);

	TVector3 v6(3,-1,0);
	this->iVertices.push_back(v6*aScale);

	TVector3 v7(3,-2,2);
	this->iVertices.push_back(v7*aScale);

	TVector3 v8(5,0,2);
	this->iVertices.push_back(v8*aScale);

/*
	TTriangle t0(0,2,1);
	this->iTriangles.push_back(t0);


	TTriangle t1(0,3,2);
	this->iTriangles.push_back(t1);


	TTriangle t2(0,1,4);
	this->iTriangles.push_back(t2);


	TTriangle t3(1,5,4);
	this->iTriangles.push_back(t3);


	TTriangle t4(1,6,5);
	this->iTriangles.push_back(t4);


	TTriangle t5(1,2,6);
	this->iTriangles.push_back(t5);


	TTriangle t6(2,3,6);
	this->iTriangles.push_back(t6);


	TTriangle t7(3,7,6);
	this->iTriangles.push_back(t7);


	TTriangle t8(4,5,8);
	this->iTriangles.push_back(t8);


	TTriangle t9(5,6,8);
	this->iTriangles.push_back(t9);


	TTriangle t10(6,7,8);
	this->iTriangles.push_back(t10);


	TTriangle t11(0,4,3);
	this->iTriangles.push_back(t11);


	TTriangle t12(3,4,7);
	this->iTriangles.push_back(t12);


	TTriangle t13(4,8,7);
	this->iTriangles.push_back(t13);

*/

	TTriangle t0(0,1,2);
	this->iTriangles.push_back(t0);

	TTriangle t1(0,2,3);
	this->iTriangles.push_back(t1);

	TTriangle t2(0,4,1);
	this->iTriangles.push_back(t2);

	TTriangle t3(1,4,5);
	this->iTriangles.push_back(t3);

	TTriangle t4(1,5,6);
	this->iTriangles.push_back(t4);

	TTriangle t5(1,6,2);
	this->iTriangles.push_back(t5);

	TTriangle t6(2,6,3);
	this->iTriangles.push_back(t6);

	TTriangle t7(3,6,7);
	this->iTriangles.push_back(t7);

	TTriangle t8(4,8,5);
	this->iTriangles.push_back(t8);

	TTriangle t9(5,8,6);
	this->iTriangles.push_back(t9);

	TTriangle t10(6,8,7);
	this->iTriangles.push_back(t10);

	TTriangle t11(0,3,4);
	this->iTriangles.push_back(t11);

	TTriangle t12(3,7,4);
	this->iTriangles.push_back(t12);

	TTriangle t13(4,7,8);
	this->iTriangles.push_back(t13);
	}