void DrawContoursTest::testInPlace1() { m_operator->initialize(); m_operator->activate(); runtime::DataContainer img(new cvsupport::Image("lenna.jpg")); runtime::Data* contoursItem = 0; std::vector<runtime::Data*> contoursVector; contoursItem = new cvsupport::Matrix("contour_1.npy"); contoursVector.push_back(contoursItem); contoursItem = new cvsupport::Matrix("contour_2.npy"); contoursVector.push_back(contoursItem); runtime::DataContainer contours(new runtime::List(contoursVector)); runtime::UInt8 ch1(255); runtime::UInt8 ch2(0); runtime::UInt8 ch3(0); runtime::Int32 thickness(-1); m_operator->setInputData(DrawContours::IMG, img); m_operator->setInputData(DrawContours::CONTOURS, contours); m_operator->setParameter(DrawContours::CH_1, ch1); m_operator->setParameter(DrawContours::CH_2, ch2); m_operator->setParameter(DrawContours::CH_3, ch3); m_operator->setParameter(DrawContours::THICKNESS, thickness); runtime::DataContainer imgResult = m_operator->getOutputData(DrawContours::IMG); runtime::ReadAccess imgAccess(imgResult); cvsupport::Image::save("DrawContoursTest_testInPlace1_img.png", imgAccess.get<runtime::Image>()); }
TEST(ChunkTests, HeightValuesMatchAcrossChunks) { const unsigned VOXELS_PER_CHUNK = Units::chunkToVoxel(1); DummyChunk ch1(0, 0, 0); DummyChunk ch2(1, 0, 0); DummyChunk ch3(0, 0, 1); ch1.generate(); ch2.generate(); ch3.generate(); EXPECT_EQ(ch1.heightAt(VOXELS_PER_CHUNK, 0), ch2.heightAt(0, 0)); }
void setPWM(int channel, int value) //set "channel" in PWM mode with duty = "value" { float duty = ((float) value)/100; switch(channel) { case 0 : PwmOut ch0(LED1); ch0 = 1 - duty; ch0.period(pwmPeriod); break; case 1 : PwmOut ch1(LED2); ch1 = 1 - duty; ch1.period(pwmPeriod); break; case 2 : PwmOut ch2(LED3); ch2 = 1 - duty; ch2.period(pwmPeriod); break; case 3 : PwmOut ch3(D5); ch3 = duty; ch3.period(pwmPeriod); break; case 4 : PwmOut ch4(PTE29); ch4 = duty; ch4.period(pwmPeriod); break; case 5 : PwmOut ch5(PTE21); ch5 = duty; ch5.period(pwmPeriod); break; //Define more outputs here. No need to change UI code upon addition of outputs default : break; } }
TEST_F(test_core, transition_NNIS) { // define additional node chains NodeChain<M1> ch1(4, 100), ch2(6, 200), ch3(2, 300); // define network entry. link(ch1[0], pass, atNegative, 1); // N ch1. back(). link(term, digits, atSimple, -1); entry. link(ch2[0], pass, atNegative, 2); // N ch2. back(). link(term, letters, atSimple, -2); entry. link(ch3[0], pass, atInvoke, 3); // I ch3. back(). link(exit, alpha, atSimple, 4); ch3. back(). link(exit, _12345, atSimple, 5); ch3. back(). link(exit, pound, atSimple, 6); entry. link(exit, pass, atSimple, 7); // S exit. link(term, end, atSimple, 8); // test parsing EXPECT_EQ( 0, trace_count(entry, "alpha", 2048) ); EXPECT_EQ( 0, trace_count(entry, "12345", 2048) ); EXPECT_EQ( 1, trace_count(entry, "#", 2048) ); }
void switchIO(int channel, int value) //Turn "channel" ON/OFF { int signal = value; switch(channel) { case 0 : DigitalOut ch0(LED1); ch0 = 1 - signal; break; case 1 : DigitalOut ch1(LED2); ch1 = 1 - signal; break; case 2 : DigitalOut ch2(LED3); ch2 = 1 - signal; break; case 3 : DigitalOut ch3(D5); ch3 = signal; break; case 4 : DigitalOut ch4(PTE29); ch4 = signal; break; case 5 : DigitalOut ch5(PTE21); ch5 = signal; break; //Define more outputs here default : break; } }
void lc_tankdlg::sideview(double leng, double x,double breadth,double height,double r, double CH,Document_Interface *doc) { QPointF Coord_a,Coord_i(0.0+leng+x,0.0+breadth+height+x), Coord_j(breadth,0.0); // side view Coord_a.setX(startxedit->text().toDouble()); Coord_a.setY(startyedit->text().toDouble()); Coord_i += Coord_a, Coord_j += Coord_i; QPointF Coord_k(0.0,height),Coord_l(0.0,0.0-height); Coord_k = Coord_j-Coord_k, Coord_l += Coord_i; QPointF mid3_b(breadth/2-r,0.0), mid4_b(breadth/2+r,0.0); //tank side view mid3_b += Coord_i, mid4_b += Coord_i; QPointF ch3(0.0,CH), ch4(0.0,CH); ch3 += mid3_b, ch4 +=mid4_b; doc->addLine(&Coord_l, &Coord_i); //Coord_i to Coord_l for side view doc->addLine(&Coord_i, &Coord_j); doc->addLine(&Coord_j, &Coord_k); doc->addLine(&Coord_k, &Coord_l); doc->addLine(&mid3_b, &ch3);// side view of tank doc->addLine(&mid4_b,&ch4); doc->addLine(&ch3, &ch4); }
void MinimumVolumeBox3DWindow::CreateScene() { mScene = std::make_shared<Node>(); std::mt19937 mte; std::uniform_real_distribution<float> rnd(-1.0f, 1.0f); Vector3<float> center{ 0.0f, 0.0f, 0.0f }; Vector3<float> extent{ 1.0f, 0.25f, 0.125f }; Vector3<float> axis[3] = { { 1.0f, 1.0f, 0.0f }, { -1.0f, 1.0f, 0.0f }, { 0.0f, 0.0f, 1.0f } }; Normalize(axis[0]); Normalize(axis[1]); Normalize(axis[2]); for (auto& v : mVertices) { float theta = rnd(mte) * (float)GTE_C_TWO_PI; float phi = rnd(mte) * (float)GTE_C_PI; float radius = 0.5f * (rnd(mte) + 1.0f); float x = extent[0] * cos(theta) * sin(phi); float y = extent[1] * sin(theta) * sin(phi); float z = extent[2] * cos(phi); v = center + radius * (x * axis[0] + y * axis[1] + z * axis[2]); } struct Vertex { Vector3<float> position; Vector4<float> color; }; VertexFormat vformat; vformat.Bind(VA_POSITION, DF_R32G32B32_FLOAT, 0); vformat.Bind(VA_COLOR, DF_R32G32B32A32_FLOAT, 0); std::shared_ptr<VertexBuffer> vbuffer(new VertexBuffer(vformat, NUM_POINTS)); Vertex* vertex = vbuffer->Get<Vertex>(); for (int i = 0; i < NUM_POINTS; ++i) { vertex[i].position[0] = (float)mVertices[i][0]; vertex[i].position[1] = (float)mVertices[i][1]; vertex[i].position[2] = (float)mVertices[i][2]; vertex[i].color[0] = 0.5f * (rnd(mte) + 1.0f); vertex[i].color[1] = 0.5f * (rnd(mte) + 1.0f); vertex[i].color[2] = 0.5f * (rnd(mte) + 1.0f); vertex[i].color[3] = 1.0f; } std::shared_ptr<IndexBuffer> ibuffer(new IndexBuffer(IP_POLYPOINT, NUM_POINTS)); std::shared_ptr<VertexColorEffect> effect = std::make_shared<VertexColorEffect>(mProgramFactory); mPoints = std::make_shared<Visual>(vbuffer, ibuffer, effect); mCameraRig.Subscribe(mPoints->worldTransform, effect->GetPVWMatrixConstant()); mScene->AttachChild(mPoints); // Choose the number of threads to use. The default constructor for // MinimumVolumeBox3 uses a default of 1, in which case all computations // are on the main thread. The timings below are for a 64-bit release // build (no debugger attached) on Intel Core i7-3930K CPUs running at // 3.20 GHz. unsigned int numThreads = 1; #if 0 // Compute the convex hull internally using arbitrary precision // arithmetic. This is slower than computing the hull explicitly using // the maximum fixed precision; see the other conditional block of code. Timer timer; typedef BSRational<UIntegerAP32> MVBRational; MinimumVolumeBox3<float, MVBRational> mvb3(numThreads); OrientedBox3<float> minBox = mvb3(NUM_POINTS, &mVertices[0]); std::cout << "mvb3 seconds = " << timer.GetSeconds() << std::endl; // numThreads = 1, seconds = 7.09 // numThreads = 2, seconds = 6.22 #else // If mVertices were to use 'double', you would need the template type // UIntegerFP32<167> to compute the convex hull. Timer timer; typedef BSNumber<UIntegerFP32<27>> CHRational; ConvexHull3<float, CHRational> ch3(numThreads); ch3(NUM_POINTS, &mVertices[0], 0.0f); std::vector<TriangleKey<true>> const& triangles = ch3.GetHullUnordered(); int const numIndices = static_cast<int>(3 * triangles.size()); int const* indices = static_cast<int const*>(&triangles[0].V[0]); typedef BSRational<UIntegerAP32> MVBRational; MinimumVolumeBox3<float, MVBRational> mvb3(numThreads); OrientedBox3<float> minBox = mvb3(NUM_POINTS, &mVertices[0], numIndices, indices); std::cout << "mvb3 seconds = " << timer.GetSeconds() << std::endl; // numThreads = 1, seconds = 2.69 // numThreads = 2, seconds = 2.01 #endif std::vector<int> const& hull = mvb3.GetHull(); ibuffer = std::make_shared<IndexBuffer>(IP_TRIMESH, static_cast<int>(hull.size() / 3), sizeof(int)); Memcpy(ibuffer->GetData(), &hull[0], ibuffer->GetNumBytes()); mPolytope = std::make_shared<Visual>(vbuffer, ibuffer, effect); mScene->AttachChild(mPolytope); MeshFactory mf; mf.SetVertexFormat(vformat); mBoxMesh = mf.CreateBox(1.0f, 1.0f, 1.0f); vbuffer = mBoxMesh->GetVertexBuffer(); vertex = vbuffer->Get<Vertex>(); std::array<Vector3<float>, 8> corner; minBox.GetVertices(corner); for (int i = 0; i < 8; ++i) { vertex[i].position[0] = corner[i][0]; vertex[i].position[1] = corner[i][1]; vertex[i].position[2] = corner[i][2]; vertex[i].color[0] = 0.5f * (rnd(mte) + 1.0f); vertex[i].color[1] = 0.5f * (rnd(mte) + 1.0f); vertex[i].color[2] = 0.5f * (rnd(mte) + 1.0f); vertex[i].color[3] = 1.0f; } mBoxMesh->SetEffect(effect); mScene->AttachChild(mBoxMesh); mTrackball.Attach(mScene); mTrackball.Update(); }