/* >>> start tutorial code >>> */ int main( ) { USING_NAMESPACE_ACADO VariablesGrid grid1( 1,0.0,5.0,6 ); VariablesGrid grid2( 1,0.0,8.0,9 ); for( int i=0; i<6; ++i ) grid1( i,0 ) = (double)i; for( int i=0; i<9; ++i ) grid2( i,0 ) = (double)i*2.0; grid1.print("grid1"); grid2.print("grid2"); grid2.merge( grid1, MM_REPLACE, BT_TRUE ); grid2.print("modified grid1"); return 0; }
void convert_to_sdf(int width, int height, unsigned char* data, float radius) { Grid grid1(width, height); // Points inside Grid grid2(width, height); // Points outside for (int y = 0, xy = 0; y < height; ++y) // for each row { for (int x = 0; x < width; ++x, ++xy) // for each pixel in row { register Point* p1, *p2; if (data[xy] < 128) p1 = &inside, p2 = ∅ else p1 = &empty, p2 = &inside; // Points inside get marked with a dx/dy of zero. // Points outside get marked with an infinitely large distance. grid1[xy] = *p1; grid2[xy] = *p2; } } generate_sdf_grid(grid1); generate_sdf_grid(grid2); for (int y = 0, xy = 0; y < height; ++y) // for each row { for (int x = 0; x < width; ++x, ++xy) // for each pixel in row { // Calculate the actual distance from the dx/dy float dist1 = sqrtf((float) grid1[xy].dist_sq ); float dist2 = sqrtf((float) grid2[xy].dist_sq ); //float dist = dist1 - dist2; //dist = dist * 3 + 128.0f; //if (dist > 255.0f) dist = 255.0f; //else if (dist < 0.0f) dist = 0.0f; //data[xy] = (unsigned char)(dist); float dist = (dist1 - dist2) / radius; dist = (dist * 0.5f) + 0.5f; if (dist > 1.0f) dist = 1.0f; else if (dist < 0.0f) dist = 0.0f; data[xy] = (unsigned char)(dist * 255.0f); } } }
TEST_F(BeatsTranslateTest, SimpleTranslateMatch) { // Set up BeatGrids for decks 1 and 2. const double bpm = 60.0; const double firstBeat = 0.0; BeatGrid grid1(m_pTrack1.data(), m_pTrack1->getSampleRate()); grid1.setGrid(bpm, firstBeat); m_pTrack1->setBeats(QSharedPointer<Beats>(&grid1)); ASSERT_DOUBLE_EQ(firstBeat, grid1.findClosestBeat(0)); BeatGrid grid2(m_pTrack2.data(), m_pTrack2->getSampleRate()); grid2.setGrid(bpm, firstBeat); m_pTrack2->setBeats(QSharedPointer<Beats>(&grid2)); ASSERT_DOUBLE_EQ(firstBeat, grid2.findClosestBeat(0)); // Seek deck 1 forward a bit. const double delta = 2222.0; m_pChannel1->getEngineBuffer()->slotControlSeekAbs(delta); ProcessBuffer(); EXPECT_TRUE(m_pChannel1->getEngineBuffer()->getVisualPlayPos() > 0); // Make both decks playing. ControlObject::getControl(m_sGroup1, "play", true)->set(1.0); ControlObject::getControl(m_sGroup2, "play", true)->set(1.0); ProcessBuffer(); // Manually set the "bpm" control... I would like to figure out why this // doesn't get set naturally, but this will do for now. QScopedPointer<ControlObjectThread> pBpm1(getControlObjectThread( ConfigKey(m_sGroup1, "bpm"))); QScopedPointer<ControlObjectThread> pBpm2(getControlObjectThread( ConfigKey(m_sGroup1, "bpm"))); pBpm1->set(bpm); pBpm2->set(bpm); ProcessBuffer(); // Push the button on deck 2. QScopedPointer<ControlObjectThread> (getControlObjectThread( ConfigKey(m_sGroup2, "beats_translate_match_alignment")))->set(1.0); ProcessBuffer(); // Deck 1 is +delta away from its closest beat (which is at 0). // Deck 2 was left at 0. We translated grid 2 so that it is also +delta // away from its closest beat, so that beat should be at -delta. ASSERT_DOUBLE_EQ(-delta, grid2.findClosestBeat(0)); }
int main(int argc, char* argv[]) { // command line error check if (argc < 2) { std::cout << "Usage: " << argv[0] << " [--help] infile [outfile]\n\n"; exit(-1); } // help diagnostic if (std::string(argv[1]) == "--help") { std::cout << argv[0] << ": convert MMSP PFgrid data format to sparsePF data format.\n"; std::cout << "Usage: " << argv[0] << " [--help] infile [outfile]\n\n"; std::cout << "Questions/comments to [email protected] (Jason Gruber).\n\n"; exit(0); } // file open error check std::ifstream input(argv[1]); if (!input) { std::cerr << "File input error: could not open " << argv[1] << ".\n\n"; exit(-1); } // generate output file name std::stringstream filename; if (argc < 3) filename << std::string(argv[1]).substr(0, std::string(argv[1]).find_last_of(".")) << ".sPF"; else filename << argv[2]; // read data type std::string type; getline(input, type, '\n'); // grid type error check if (type.substr(0, 4) != "grid") { std::cerr << "File input error: file does not contain grid data." << std::endl; exit(-1); } // parse data type bool bool_type = (type.find("bool") != std::string::npos); bool char_type = (type.find("char") != std::string::npos); bool unsigned_char_type = (type.find("unsigned char") != std::string::npos); bool int_type = (type.find("int") != std::string::npos); bool unsigned_int_type = (type.find("unsigned int") != std::string::npos); bool long_type = (type.find("long") != std::string::npos); bool unsigned_long_type = (type.find("unsigned long") != std::string::npos); bool short_type = (type.find("short") != std::string::npos); bool unsigned_short_type = (type.find("unsigned short") != std::string::npos); bool float_type = (type.find("float") != std::string::npos); bool double_type = (type.find("double") != std::string::npos); bool long_double_type = (type.find("long double") != std::string::npos); bool scalar_type = (type.find("scalar") != std::string::npos); bool vector_type = (type.find("vector") != std::string::npos); bool sparse_type = (type.find("sparse") != std::string::npos); if (not bool_type and not char_type and not unsigned_char_type and not int_type and not unsigned_int_type and not long_type and not unsigned_long_type and not short_type and not unsigned_short_type and not float_type and not double_type and not long_double_type) { std::cerr << "File input error: unknown grid data type." << std::endl; exit(-1); } // check for valid MCgrid data if (not vector_type or not double_type) { std::cerr << "File input error: data must be of type vector::double." << std::endl; exit(-1); } // read grid dimension int dim; input >> dim; if (not dim == 1 and not dim == 2 and not dim == 3) { std::cerr << "File input error: grid dimension must be 1, 2, or 3." << std::endl; exit(-1); } if (dim == 1) { MMSP::grid<1, MMSP::vector<double> > grid1(argv[1]); int x0 = MMSP::x0(grid1); int x1 = MMSP::x1(grid1); int fields = MMSP::fields(grid1); double epsilon = 1.0e-8; MMSP::grid<1, MMSP::sparse<double> > grid2(0, x0, x1); for (int i = 0; i < MMSP::nodes(grid1); i++) for (int j = 0; j < fields; j++) if (grid1(i)[j] > epsilon) MMSP::set(grid2(i), j) = grid1(i)[j]; MMSP::output(grid2, filename.str().c_str()); } if (dim == 2) { MMSP::grid<2, MMSP::vector<double> > grid1(argv[1]); int x0 = MMSP::x0(grid1); int x1 = MMSP::x1(grid1); int y0 = MMSP::y0(grid1); int y1 = MMSP::y1(grid1); int fields = MMSP::fields(grid1); double epsilon = 1.0e-8; MMSP::grid<2, MMSP::sparse<double> > grid2(0, x0, x1, y0, y1); for (int i = 0; i < MMSP::nodes(grid1); i++) for (int j = 0; j < fields; j++) if (grid1(i)[j] > epsilon) MMSP::set(grid2(i), j) = grid1(i)[j]; MMSP::output(grid2, filename.str().c_str()); } if (dim == 3) { MMSP::grid<3, MMSP::vector<double> > grid1(argv[1]); int x0 = MMSP::x0(grid1); int x1 = MMSP::x1(grid1); int y0 = MMSP::y0(grid1); int y1 = MMSP::y1(grid1); int z0 = MMSP::z0(grid1); int z1 = MMSP::z1(grid1); int fields = MMSP::fields(grid1); double epsilon = 1.0e-8; MMSP::grid<3, MMSP::sparse<double> > grid2(0, x0, x1, y0, y1, z0, z1); for (int i = 0; i < MMSP::nodes(grid1); i++) for (int j = 0; j < fields; j++) if (grid1(i)[j] > epsilon) MMSP::set(grid2(i), j) = grid1(i)[j]; MMSP::output(grid2, filename.str().c_str()); } }
Scene * D3D::BuildScene(IDirect3DDevice9 *d3dDevice) { // Setup some materials - we'll use these for // making the same mesh appear in multiple // colors D3DMATERIAL9 colors[8]; D3DUtil_InitMaterial( colors[0], 1.0f, 1.0f, 1.0f, 1.0f ); // white D3DUtil_InitMaterial( colors[1], 0.0f, 1.0f, 1.0f, 1.0f ); // cyan D3DUtil_InitMaterial( colors[2], 1.0f, 0.0f, 0.0f, 1.0f ); // red D3DUtil_InitMaterial( colors[3], 0.0f, 1.0f, 0.0f, 1.0f ); // green D3DUtil_InitMaterial( colors[4], 0.0f, 0.0f, 1.0f, 1.0f ); // blue D3DUtil_InitMaterial( colors[5], 0.4f, 0.4f, 0.4f, 0.4f ); // 40% grey D3DUtil_InitMaterial( colors[6], 0.25f, 0.25f, 0.25f, 0.25f ); // 25% grey D3DUtil_InitMaterial( colors[7], 0.65f, 0.65f, 0.65f, 0.65f ); // 65% grey // The identity matrix is always useful D3DXMATRIX ident; D3DXMatrixIdentity(&ident); // We'll use these rotations for some teapots and grid objects D3DXMATRIX rotateX, rotateY, rotateZ; // Create the root, and the camera. // Remeber how to use smart pointers?? I hope so! boost::shared_ptr<TransformNode> root(new TransformNode(&ident)); boost::shared_ptr<CameraNode> camera(new CameraNode(&ident)); root->m_children.push_back(camera); // We'll put the camera in the scene at (20,20,20) looking back at the Origin D3DXMATRIX rotOnly, result, inverse; float cameraYaw = - (3.0f * D3DX_PI) / 4.0f; float cameraPitch = D3DX_PI / 4.0f; D3DXQUATERNION q; D3DXQuaternionIdentity(&q); D3DXQuaternionRotationYawPitchRoll(&q, cameraYaw, cameraPitch, 0.0); D3DXMatrixRotationQuaternion(&rotOnly, &q); D3DXMATRIX trans; D3DXMatrixTranslation(&trans, 15.0f, 15.0f, 15.0f); D3DXMatrixMultiply(&result, &rotOnly, &trans); D3DXMatrixInverse(&inverse, NULL, &result); camera->VSetTransform(&result, &inverse); D3DXMatrixRotationZ(&rotateZ, D3DX_PI / 2.0f); D3DXMatrixRotationX(&rotateX, -D3DX_PI / 2.0f); D3DXVECTOR3 target(30, 2, 15); // ID3DXMesh *teapot; if( SUCCEEDED( D3DXCreateTeapot( d3dDevice, &teapot, NULL ) ) ) { // Teapot #1 - a white one at (x=6,y=2,z=4) D3DXMatrixTranslation(&trans,6,2,4); boost::shared_ptr<SceneNode> mesh1(new MeshNode(teapot, &trans, colors[2])); root->m_children.push_back(mesh1); // Teapot #2 - a cyan one at (x=3,y=2,z=1) // with a D3DXMatrixTranslation(&trans, 3,2,1); D3DXMATRIX result; D3DXMatrixMultiply(&result, &rotateZ, &trans); boost::shared_ptr<SceneNode> mesh2(new MeshNode(teapot, &result, colors[1])); root->m_children.push_back(mesh2); // Teapot #3 - another white one at (x=30, y=2, z=15) D3DXMATRIX rotateY90; D3DXMatrixRotationY(&rotateY90, D3DX_PI / 2.0f); D3DXMatrixTranslation(&trans, target.x, target.y, target.z); D3DXMatrixMultiply(&result, &rotateY90, &trans); boost::shared_ptr<SceneNode> mesh3(new MeshNode(teapot, &result, colors[0])); root->m_children.push_back(mesh3); // We can release the teapot now, mesh1 and mesh2 AddRef'd it. SAFE_RELEASE(teapot); } ID3DXMesh *sphere; if ( SUCCEEDED( D3DXCreateSphere( d3dDevice, .25, 16, 16, &sphere, NULL) ) ) { // We're going to create a spiral of spheres... // starting at (x=3, y=0, z=3), and spiraling // upward about a local Y axis. D3DXMatrixTranslation(&trans, 3,0,3); boost::shared_ptr<SceneNode> sphere1(new MeshNode(sphere, &trans, colors[4]) ); root->m_children.push_back(sphere1); // Here's the local rotation and translation. // We'll rotate about Y, and then translate // up (along Y) and forward (along Z). D3DXMatrixRotationY(&rotateY, D3DX_PI / 8.0f); D3DXMATRIX trans2; D3DXMatrixTranslation(&trans2, 0, 0.5, 0.5); D3DXMatrixMultiply(&result, &trans2, &rotateY); for (int i=0; i<25; i++) { // If you didn't think smart pointers were cool - // watch this! No leaked memory.... // Notice this is a heirarchy.... boost::shared_ptr<SceneNode> sphere2(new MeshNode(sphere, &result, colors[i%5]) ); sphere1->m_children.push_back(sphere2); sphere1 = sphere2; } // We can release the sphere now, all the cylinders AddRef'd it. SAFE_RELEASE(sphere); } // D3DXMatrixTranslation(&trans,-25,20,20); //D3DXMatrixScaling(&trans, -10, -10, -10); ScaleMtrl scale; scale.x = -50.0f; scale.y = -50.0f; scale.z = -50.0f; boost::shared_ptr<SceneNode> xmesh1(new XMeshNode(L"gf3.x", d3dDevice, &trans, &scale)); root->m_children.push_back(xmesh1); root->m_children.push_back(xmesh1); /*D3DXMatrixTranslation(&trans,-45,20,20); boost::shared_ptr<SceneNode> xmesh11(new XMeshNode(L"gf3.x", d3dDevice, &trans, &scale)); root->m_children.push_back(xmesh11);*/ XMeshNode *mm = new XMeshNode(L"gow_m1.x", d3dDevice, &trans, &scale); D3DXMatrixTranslation(&trans,10,10,10); //D3DXMatrixScaling(&trans, -10, -10, -10); //ScaleMtrl scale; scale.x = 100.0f; scale.y = 100.0f; scale.z = 100.0f; boost::shared_ptr<SceneNode> xmesh2( new XMeshNode(L"gow_m1.x", d3dDevice, &trans, &scale)); root->m_children.push_back(xmesh2); /*D3DXMatrixTranslation(&trans,20,20,20); boost::shared_ptr<SceneNode> xmesh3(new XMeshNode(mm->m_mesh, mm->Mtrls, mm->Textures, &trans, 0)); root->m_children.push_back(xmesh3);*/ int col = 10; int row= 10; int zoom = 10; const int COUNT = 13; for(int i = 0; i < COUNT; i++) { for (int j = 0; j< COUNT; j++) { for(int z = 0; z< COUNT; z++) { D3DXMatrixTranslation(&trans, col + i, row + j , zoom + z); boost::shared_ptr<SceneNode> xmeshNew(new XMeshNode(mm->m_mesh, mm->Mtrls, mm->Textures, &trans, 0)); root->m_children.push_back(xmeshNew); } } } //D3DXMatrixScaling(&trans, 10, 10, 10); // Here are the grids...they make it easy for us to // see where the coordinates are in 3D space. boost::shared_ptr<SceneNode> grid1(new Grid(40, 0x00404040, L"Textures\\grid.dds", &ident)); root->m_children.push_back(grid1); boost::shared_ptr<SceneNode> grid2(new Grid(40, 0x00004000, L"Textures\\grid.dds", &rotateX)); root->m_children.push_back(grid2); boost::shared_ptr<SceneNode> grid3(new Grid(40, 0x00000040, L"Textures\\grid.dds", &rotateZ)); root->m_children.push_back(grid3); // Here's the sky node that never worked!!!! boost::shared_ptr<SkyNode> sky(new SkyNode(_T("Sky2"), camera)); root->m_children.push_back(sky); D3DXMatrixTranslation(&trans,15,2,15); D3DXMatrixRotationY(&rotateY, D3DX_PI / 4.0f); D3DXMatrixMultiply(&result, &rotateY, &trans); boost::shared_ptr<SceneNode> arrow1(new ArrowNode(2, &result, colors[0], d3dDevice)); root->m_children.push_back(arrow1); D3DXMatrixRotationY(&rotateY, D3DX_PI / 2.0f); D3DXMatrixMultiply(&result, &rotateY, &trans); boost::shared_ptr<SceneNode> arrow2(new ArrowNode(2, &result, colors[5], d3dDevice)); root->m_children.push_back(arrow2); D3DXMatrixMultiply(&result, &rotateX, &trans); boost::shared_ptr<SceneNode> arrow3(new ArrowNode(2, &result, colors[0], d3dDevice)); root->m_children.push_back(arrow3); // Everything has been attached to the root. Now // we attach the root to the scene. Scene *scene = new Scene(d3dDevice, root); scene->Restore(); // A movement controller is going to control the camera, // but it could be constructed with any of the objects you see in this // function. You can have your very own remote controlled sphere. What fun... boost::shared_ptr<MovementController> m_pMovementController(new MovementController(camera, cameraYaw, cameraPitch)); scene->m_pMovementController = m_pMovementController; return scene; }