void Game::RefreshRendering(){ SwitchCircles.clear(); TrapBoxes.clear(); WiringLines.clear(); SwitchCircles.resize(track->Traps.size()); TrapBoxes.resize(track->Traps.size()); WiringLines.resize(track->Traps.size()); for (unsigned i=0; i<track->Traps.size(); i++) { Trap& trap=track->Traps[i]; SwitchCircles[i].resize(trap.SwitchPositions.size()); TrapBoxes[i].resize(trap.trapData.size()); WiringLines[i].resize(trap.Wiring.size()); bool MainSwitch=trap.MainSwitch; for (unsigned j=0; j<trap.SwitchPositions.size(); j++) { Vector2d SwitchPosition=ScalePosition(Vector2d(trap.SwitchPositions[j].x+0.5, trap.SwitchPositions[j].y+0.5) , Scaling, paddingdim, padding); if (MainSwitch==0) SwitchCircles[i][j]=CreateCircle(0.3*Scaling,sf::Color::Yellow,SwitchPosition); else SwitchCircles[i][j]=CreateCircle(0.3*Scaling,sf::Color::Green,SwitchPosition); } for (unsigned j=0; j<trap.trapData.size(); j++) { Vector2u TrapPosUnsigned=trap.trapData[j].Square; Tile* CurrentTile=track->getTile(TrapPosUnsigned.x,TrapPosUnsigned.y); bool isSquare=CurrentTile->isSquare; unsigned Orientation=CurrentTile->Orientation; bool Half=trap.trapData[j].Half; Vector2d TrapPosition=ScalePosition(Vector2d(TrapPosUnsigned.x+0.5, TrapPosUnsigned.y+0.5) , Scaling, paddingdim, padding); if (trap.MainSwitch==1 && isSquare) TrapBoxes[i][j]=CreateLineBox(TrapPosition, Scaling, sf::Color::Yellow); if (trap.MainSwitch==0 && isSquare) TrapBoxes[i][j]=CreateLineBox(TrapPosition, Scaling, sf::Color::Red); if (trap.MainSwitch==1 && !isSquare) TrapBoxes[i][j]=CreateLineTriangle(TrapPosition,Orientation,Half, Scaling, sf::Color::Yellow); if (trap.MainSwitch==0 && !isSquare) TrapBoxes[i][j]=CreateLineTriangle(TrapPosition,Orientation,Half, Scaling, sf::Color::Red); } for (unsigned j=0; j<trap.Wiring.size(); j++) { Vector2d StartPos=trap.Wiring[j].first; Vector2d EndPos=trap.Wiring[j].second; StartPos=ScalePosition(StartPos, Scaling, paddingdim, padding); EndPos=ScalePosition(EndPos, Scaling, paddingdim, padding); if(trap.MainSwitch==0) WiringLines[i][j]=CreateLine(StartPos,EndPos,sf::Color::Red); else WiringLines[i][j]=CreateLine(StartPos,EndPos,sf::Color::Yellow); } } }
VOID KLine::createResizeTip() { if( _bTipEnable == TRUE && _bLeftTopTipActive == FALSE && _bRightBottomTipActive == FALSE ) { _shLeftTopTip = (KCircle*)CreateCircle(_p, _rgbaTipLineColor, _rgbaTipFillColor, _l, _t, _fTipSize/2); _shRightBottomTip = (KCircle*)CreateCircle(_p, _rgbaTipLineColor, _rgbaTipFillColor, _r, _b, _fTipSize/2); _shLeftTopTip->regen(); _shRightBottomTip->regen(); } }
PhysBody* ModulePhysics::CreateFlipper(bool isbullet, int angle_upper, int angle_lower, SDL_Texture* texture, int flipper_pos_x, int flipper_pos_y, int pivot_pos_x, int pivot_pos_y, int radious, int* points, uint size, float density, float restitution, bool ccd, bool isSensor, int localAnchorA_x, int localAnchorA_y, int localAnchorB_x, int localAnchorB_y) { PhysBody* Circle = CreateCircle(pivot_pos_x, pivot_pos_y, radious, 1, isSensor, isbullet, 0); PhysBody* Flipper = CreateChain(flipper_pos_x, flipper_pos_y, points, size, density, restitution, isSensor, texture); //JOINT b2RevoluteJointDef Revolute_Joint_Def; Revolute_Joint_Def.bodyA = Flipper->body; Revolute_Joint_Def.bodyB = Circle->body; Revolute_Joint_Def.collideConnected = false; //revolute_joint_def.enableMotor = true; //revolute_joint_def.motorSpeed = 0.0f; //revolute_joint_def.maxMotorTorque = 100.0f; if (angle_upper != INT_MAX && angle_lower != INT_MIN) { Revolute_Joint_Def.enableLimit = true; Revolute_Joint_Def.lowerAngle = DEGTORAD * angle_lower; Revolute_Joint_Def.upperAngle = DEGTORAD * angle_upper; } Revolute_Joint_Def.localAnchorA.Set(PIXEL_TO_METERS(localAnchorA_x), PIXEL_TO_METERS(localAnchorA_y)); Revolute_Joint_Def.localAnchorB.Set(PIXEL_TO_METERS(localAnchorB_x), PIXEL_TO_METERS(localAnchorB_y)); world->CreateJoint(&Revolute_Joint_Def); return Flipper; }
void Keyboard(int key) { switch (key) { case GLFW_KEY_C: CreateCircle(); break; } }
LightSource::LightSource(sf::Vector2f p_Position, float p_Radius ) { m_LightRadius = p_Radius; m_Circle = new sf::CircleShape(p_Radius); m_Circle->setPosition(p_Position); m_LightTexture = new sf::RenderTexture(); m_LightTexture->create(m_LightRadius * 2.0f, m_LightRadius * 2.0f); CreateCircle(); m_LightOn = true; }
void TfrmView::randomize() { Layer* pLayer = LayerFactory::create(_T("Randomize")); for(int i=0 ; i<100 ; i++) { Shape* pShape; SHAPE_TYPE type = rand()%3; switch(type) { case SHAPE_RECTANGLE: pShape = CreateRectangle(_pView->painter() ,RGBA(rand()%256,rand()%256,rand()%256) ,RGBA(rand()%256,rand()%256,rand()%256) ,rand()%400 - 200 ,rand()%400 - 200 ,rand()%400 - 200 ,rand()%400 - 200 ); break; case SHAPE_CIRCLE: pShape = CreateCircle(_pView->painter() ,RGBA(rand()%256,rand()%256,rand()%256) ,RGBA(rand()%256,rand()%256,rand()%256) ,rand()%400 - 200 ,rand()%400 - 200 ,rand()%100 ); break; case SHAPE_LINE: pShape = CreateLine(_pView->painter() ,RGBA(rand()%256,rand()%256,rand()%256) ,rand()%400 - 200 ,rand()%400 - 200 ,rand()%400 - 200 ,rand()%400 - 200 ); break; } pLayer->insert(pShape); } _pView->layers()->insert(pLayer); _pView->layers()->regen(); this->FormPaint(this); }
void ParseCommands(const std::vector<std::vector<std::string>>& commands, std::vector<std::shared_ptr<CShape>>& figures, std::vector<std::shared_ptr<sf::Shape>>& drawableFigures) { for (const auto& command : commands) { try { std::cout << "> Parsing:" << std::endl; std::copy(command.begin(), command.end(), std::ostream_iterator<std::string>(std::cout, " ")); std::cout << std::endl; if (command[0] == "rectangle") { CreateRectangle(command, figures, drawableFigures); } else if (command[0] == "circle") { CreateCircle(command, figures, drawableFigures); } else if (command[0] == "line") { CreateLine(command, figures, drawableFigures); } else if (command[0] == "triangle") { CreateTriangle(command, figures, drawableFigures); } else if (command[0] == "point") { CreatePoint(command, figures, drawableFigures); } else { throw std::exception("\tError: Invalid command"); } } catch (const std::exception& error) { std::cout << error.what() << std::endl; } } }
PhysBody* ModulePhysics::CreateGear(int x, int y, int width, int height, int radius) { PhysBody* tmp1; PhysBody* tmp2; tmp1 = CreateCircle(x, y, radius, 1, false, false, 0, GEAR); tmp2 = CreateRectangle(x, y, width, height, 0, 2, 0, GEAR); b2RevoluteJointDef defr; defr.bodyA = tmp1->body; defr.bodyB = tmp2->body; defr.localAnchorA = b2Vec2(0, 0); defr.localAnchorB = b2Vec2(0, 0); defr.collideConnected = false; defr.enableMotor = true; defr.maxMotorTorque = 0.1f; world->CreateJoint(&defr); return tmp2; }
WOGScene* OGSceneConfig::Parser() { WOGScene* scene = new WOGScene; scene->minx = rootElement.attribute("minx").toDouble(); scene->miny = rootElement.attribute("miny").toDouble(); scene->maxx = rootElement.attribute("maxx").toDouble(); scene->maxy = rootElement.attribute("maxy").toDouble(); scene->backgroundcolor = StringToColor(rootElement.attribute("backgroundcolor")); QDomNode node = rootElement.firstChild(); while (!node.isNull()) { QDomElement domElement = node.toElement(); if (domElement.tagName() == "SceneLayer") { scene->sceneLayer << CreateSceneLayer(domElement); } else if (domElement.tagName() == "label") { scene->label << CreateLabel(domElement); } else if (domElement.tagName() == "buttongroup") { scene->buttongroup << CreateButtonGroup(domElement); } else if (domElement.tagName() == "button") { scene->button << CreateButton(domElement); } else if (domElement.tagName() == "radialforcefield") { scene->radialforcefield << CreateRadialForceField(domElement); } else if (domElement.tagName() == "linearforcefield") { scene->linearforcefield << CreateLinearForceField(domElement); } else if (domElement.tagName() == "particles") { scene->particle << CreateParticle(domElement); } else if (domElement.tagName() == "circle") { scene->circle << CreateCircle(domElement); } else if (domElement.tagName() == "line") { scene->line << CreateLine(domElement); } else if (domElement.tagName() == "rectangle") { scene->rectangle << CreateRectanle(domElement); } node = node.nextSibling(); } return scene; }
update_status ModulePhysics::PostUpdate() { // On space bar press, create a circle on mouse position if(App->input->GetKey(SDL_SCANCODE_1) == KEY_DOWN) { CreateCircle(App->input->GetMouseX(), App->input->GetMouseY(), 50); } if(App->input->GetKey(SDL_SCANCODE_2) == KEY_DOWN) { // TODO 1: When pressing 2, create a box on the mouse position CreateRectangle(App->input->GetMouseX(), App->input->GetMouseY(), 2.0f , 3.0f); // TODO 2: To have the box behave normally, set fixture's density to 1.0f } if(App->input->GetKey(SDL_SCANCODE_3) == KEY_DOWN) { // TODO 3: Create a chain shape using those vertices // remember to convert them from pixels to meters! //CreateChain(); } if(App->input->GetKey(SDL_SCANCODE_F1) == KEY_DOWN) debug = !debug; if(!debug) return UPDATE_CONTINUE; // Bonus code: this will iterate all objects in the world and draw the circles // You need to provide your own macro to translate meters to pixels for(b2Body* b = world->GetBodyList(); b; b = b->GetNext()) { for(b2Fixture* f = b->GetFixtureList(); f; f = f->GetNext()) { switch(f->GetType()) { // Draw circles ------------------------------------------------ case b2Shape::e_circle: { b2CircleShape* shape = (b2CircleShape*)f->GetShape(); b2Vec2 pos = f->GetBody()->GetPosition(); App->renderer->DrawCircle(METERS_TO_PIXELS(pos.x), METERS_TO_PIXELS(pos.y), METERS_TO_PIXELS(shape->m_radius), 255, 255, 255); } break; // Draw polygons ------------------------------------------------ case b2Shape::e_polygon: { b2PolygonShape* polygonShape = (b2PolygonShape*)f->GetShape(); int32 count = polygonShape->GetVertexCount(); b2Vec2 prev, v; for(int32 i = 0; i < count; ++i) { v = b->GetWorldPoint(polygonShape->GetVertex(i)); if(i > 0) App->renderer->DrawLine(METERS_TO_PIXELS(prev.x), METERS_TO_PIXELS(prev.y), METERS_TO_PIXELS(v.x), METERS_TO_PIXELS(v.y), 255, 100, 100); prev = v; } v = b->GetWorldPoint(polygonShape->GetVertex(0)); App->renderer->DrawLine(METERS_TO_PIXELS(prev.x), METERS_TO_PIXELS(prev.y), METERS_TO_PIXELS(v.x), METERS_TO_PIXELS(v.y), 255, 100, 100); } break; // Draw chains contour ------------------------------------------- case b2Shape::e_chain: { b2ChainShape* shape = (b2ChainShape*)f->GetShape(); b2Vec2 prev, v; for(int32 i = 0; i < shape->m_count; ++i) { v = b->GetWorldPoint(shape->m_vertices[i]); if(i > 0) App->renderer->DrawLine(METERS_TO_PIXELS(prev.x), METERS_TO_PIXELS(prev.y), METERS_TO_PIXELS(v.x), METERS_TO_PIXELS(v.y), 100, 255, 100); prev = v; } v = b->GetWorldPoint(shape->m_vertices[0]); App->renderer->DrawLine(METERS_TO_PIXELS(prev.x), METERS_TO_PIXELS(prev.y), METERS_TO_PIXELS(v.x), METERS_TO_PIXELS(v.y), 100, 255, 100); } break; // Draw a single segment(edge) ---------------------------------- case b2Shape::e_edge: { b2EdgeShape* shape = (b2EdgeShape*)f->GetShape(); b2Vec2 v1, v2; v1 = b->GetWorldPoint(shape->m_vertex0); v1 = b->GetWorldPoint(shape->m_vertex1); App->renderer->DrawLine(METERS_TO_PIXELS(v1.x), METERS_TO_PIXELS(v1.y), METERS_TO_PIXELS(v2.x), METERS_TO_PIXELS(v2.y), 100, 100, 255); } break; } } } return UPDATE_CONTINUE; }
void CLogo::Fire() { FLOAT intensity = .4f, lastTime = 20000.f, length = 1000.f; CAudioManager::GetInstance()->ChannelPlay(AL_CLAP_LOUD); CreateCircle(D3DXVECTOR3(65, 180, 0), intensity, &maps, lastTime, length, 0); CreateCircle(D3DXVECTOR3(170, 420, 0), intensity, &maps, lastTime, length, 0); CreateCircle(D3DXVECTOR3(117, 300, 0), intensity, &maps, lastTime, length, 0); CreateCircle(D3DXVECTOR3(250, 180, 0), intensity, &maps, lastTime, length, 1); CreateCircle(D3DXVECTOR3(355, 420, 0), intensity, &maps, lastTime, length, 1); CreateCircle(D3DXVECTOR3(250, 300, 0), intensity, &maps, lastTime, length, 1); CreateCircle(D3DXVECTOR3(435, 300, 0), intensity, &maps, lastTime, length, 2); CreateCircle(D3DXVECTOR3(540, 300, 0), intensity, &maps, lastTime, length, 2); CreateCircle(D3DXVECTOR3(487, 300, 0), intensity, &maps, lastTime, length, 2); CreateCircle(D3DXVECTOR3(620, 180, 0), intensity, &maps, lastTime, length, 3); CreateCircle(D3DXVECTOR3(725, 420, 0), intensity, &maps, lastTime, length, 3); CreateCircle(D3DXVECTOR3(620, 300, 0), intensity, &maps, lastTime, length, 3); }
update_status ModulePhysics::PostUpdate() { // On space bar press, create a circle on mouse position if(App->input->GetKey(SDL_SCANCODE_1) == KEY_DOWN) { CreateCircle(App->input->GetMouseX(), App->input->GetMouseY(), 25); } if(App->input->GetKey(SDL_SCANCODE_2) == KEY_DOWN) { CreateBox(75, 3); } if(App->input->GetKey(SDL_SCANCODE_3) == KEY_DOWN) { // TODO 3: Create a chain shape using those vertices // remember to convert them from pixels to meters! int points[66] = { 1, 76, 29, 62, 14, 35, 42, 38, 41, 0, 75, 31, 87, 4, 94, 40, 112, 34, 105, 62, 116, 66, 109, 73, 110, 80, 109, 85, 105, 93, 110, 99, 103, 104, 100, 116, 105, 124, 99, 131, 91, 142, 81, 149, 72, 149, 60, 147, 50, 138, 45, 133, 34, 136, 39, 126, 23, 124, 30, 114, 10, 103, 27, 91, 1, 76 }; b2Vec2 vs[33]; for (int i = 0, j = 0; j < 33; i+=2, j++) vs[j].Set(PIXEL_TO_METERS(points[i]), PIXEL_TO_METERS(points[i+1])); b2BodyDef H; H.type = b2_dynamicBody; H.position.Set(PIXEL_TO_METERS(App->input->GetMouseX()), PIXEL_TO_METERS(App->input->GetMouseY())); b2Body* b3 = world->CreateBody(&H); b2ChainShape shape_chain; b2FixtureDef fixture_chain; fixture_chain.shape = &shape_chain; fixture_chain.density = 1.0f; shape_chain.CreateLoop(vs, 32); b3->CreateFixture(&fixture_chain); } if(App->input->GetKey(SDL_SCANCODE_F1) == KEY_DOWN) debug = !debug; if(!debug) return UPDATE_CONTINUE; // Bonus code: this will iterate all objects in the world and draw the circles // You need to provide your own macro to translate meters to pixels for(b2Body* b = world->GetBodyList(); b; b = b->GetNext()) { for(b2Fixture* f = b->GetFixtureList(); f; f = f->GetNext()) { switch(f->GetType()) { // Draw circles ------------------------------------------------ case b2Shape::e_circle: { b2CircleShape* shape = (b2CircleShape*)f->GetShape(); b2Vec2 pos = f->GetBody()->GetPosition(); App->renderer->DrawCircle(METERS_TO_PIXELS(pos.x), METERS_TO_PIXELS(pos.y), METERS_TO_PIXELS(shape->m_radius), 255, 255, 255); } break; // Draw polygons ------------------------------------------------ case b2Shape::e_polygon: { b2PolygonShape* polygonShape = (b2PolygonShape*)f->GetShape(); int32 count = polygonShape->GetVertexCount(); b2Vec2 prev, v; for(int32 i = 0; i < count; ++i) { v = b->GetWorldPoint(polygonShape->GetVertex(i)); if(i > 0) App->renderer->DrawLine(METERS_TO_PIXELS(prev.x), METERS_TO_PIXELS(prev.y), METERS_TO_PIXELS(v.x), METERS_TO_PIXELS(v.y), 255, 100, 100); prev = v; } v = b->GetWorldPoint(polygonShape->GetVertex(0)); App->renderer->DrawLine(METERS_TO_PIXELS(prev.x), METERS_TO_PIXELS(prev.y), METERS_TO_PIXELS(v.x), METERS_TO_PIXELS(v.y), 255, 100, 100); } break; // Draw chains contour ------------------------------------------- case b2Shape::e_chain: { b2ChainShape* shape = (b2ChainShape*)f->GetShape(); b2Vec2 prev, v; for(int32 i = 0; i < shape->m_count; ++i) { v = b->GetWorldPoint(shape->m_vertices[i]); if(i > 0) App->renderer->DrawLine(METERS_TO_PIXELS(prev.x), METERS_TO_PIXELS(prev.y), METERS_TO_PIXELS(v.x), METERS_TO_PIXELS(v.y), 100, 255, 100); prev = v; } v = b->GetWorldPoint(shape->m_vertices[0]); App->renderer->DrawLine(METERS_TO_PIXELS(prev.x), METERS_TO_PIXELS(prev.y), METERS_TO_PIXELS(v.x), METERS_TO_PIXELS(v.y), 100, 255, 100); } break; // Draw a single segment(edge) ---------------------------------- case b2Shape::e_edge: { b2EdgeShape* shape = (b2EdgeShape*)f->GetShape(); b2Vec2 v1, v2; v1 = b->GetWorldPoint(shape->m_vertex0); v1 = b->GetWorldPoint(shape->m_vertex1); App->renderer->DrawLine(METERS_TO_PIXELS(v1.x), METERS_TO_PIXELS(v1.y), METERS_TO_PIXELS(v2.x), METERS_TO_PIXELS(v2.y), 100, 100, 255); } break; } } } return UPDATE_CONTINUE; }
MeshWeakPtr CMeshManager::CreateMesh(xst_castring& strName, const IInputLayout* pIL, BASIC_SHAPE eShape, xst_unknown pShapeOptions, xst_castring& strGroupName) { MeshWeakPtr pMesh = CreateMesh( strName, pIL, strGroupName ); if( pMesh->m_bIsCloned ) { return pMesh; } switch( eShape ) { case BasicShapes::BOX: { SBoxOptions Options; if( pShapeOptions != xst_null ) Options = *(SBoxOptions*)pShapeOptions; if( XST_FAILED( CreateBox( pMesh.GetPtr(), pIL, Options ) ) ) { this->DestroyResource( pMesh ); pMesh = xst_null; } } break; case BasicShapes::LINE_BOX: { SLineBoxOptions Options; if( pShapeOptions != xst_null ) Options = *(SLineBoxOptions*)pShapeOptions; if( XST_FAILED( CreateBox( pMesh.GetPtr(), pIL, Options ) ) ) { this->DestroyResource( pMesh ); pMesh = xst_null; } } break; case BasicShapes::CIRCLE: { SCircleOptions Options; if( pShapeOptions != xst_null ) Options = *(SCircleOptions*)pShapeOptions; if( XST_FAILED( CreateCircle( pMesh.GetPtr(), pIL, Options ) ) ) { this->DestroyResource( pMesh ); pMesh = xst_null; } } break; case BasicShapes::PLANE: { SPlaneOptions Options; if( pShapeOptions != xst_null ) Options = *(SPlaneOptions*)pShapeOptions; if( XST_FAILED( CreatePlane( pMesh.GetPtr(), pIL, Options ) ) ) { this->DestroyResource( pMesh ); pMesh = xst_null; } } break; case BasicShapes::RECT_2D: { SRect2DOptions Options; if( pShapeOptions != xst_null ) Options = *(SRect2DOptions*)pShapeOptions; if( XST_FAILED( CreateRect2D( pMesh.GetPtr(), pIL, Options ) ) ) { this->DestroyResource( pMesh ); pMesh = xst_null; } } break; default: { this->DestroyResource( pMesh ); pMesh = xst_null; } break; }; return pMesh; }
VOID ViewUnitEditor::DrawBall() { if (_pUnitdesigninfo == NULL) { return; } // Declare & Define a necessary variables POINTFLOAT unitSize = _pStripinfo->GetUnitSize(); POINTFLOAT unitPadding = _pUnitdesigninfo->GetUnitPadding(); POINTFLOAT ballPitch = _pUnitdesigninfo->GetBallPitch(); POINT ballCount = _pUnitdesigninfo->GetBallCountXY(); BallData* pBallData = NULL; FLOAT fRadius, fEachRadius; bool bIsChecked; // Initialize a Balls' Layer POINTFLOAT point = {0, 0}; Layer *_pLayer = LayerFactory::create(_TEXT("Unit Layer")); _layers.clearLayers(); // Initialize a Ball Colors RGBA clDefaultSheetColor = _pStripinfo->GetBallDesignDefaultSheet(); RGBA clDefaultOutlineColor = _pStripinfo->GetBallDesignOutline(); RGBA clCheckedSheetColor = _pStripinfo->GetBallDesignCheckedSheet() ; RGBA clCheckedOutlineColor = _pStripinfo->GetBallDesignOutline(); _pViewUnitPainter->setFillColor(clDefaultSheetColor); _pViewUnitPainter->setLineColor(clDefaultOutlineColor); _pViewUnitPainter->setSelectFillColr(_pStripinfo->GetSelectBallSheetColor()); _pViewUnitPainter->setSelectLineColr(_pStripinfo->GetSelectBallOutlineColor()); // Create a Balls' Layer _pLayer = LayerFactory::create(_TEXT("Ball Layer")); // Make a Ball Size & Margin's Information if (ballPitch.x < MINIMUM_PITCH) { ballPitch.x = MINIMUM_PITCH; } if (ballPitch.y < MINIMUM_PITCH) { ballPitch.y = MINIMUM_PITCH; } POINTFLOAT ballStartPoint = { -(unitSize.x / 2) + unitPadding.x, -(unitSize.y / 2) + unitPadding.y }; POINTFLOAT remainsBallPitch = {0.0f, 0.0f}; POINTFLOAT ballSize = { (unitSize.x - (unitPadding.x * 2.0f) - (ballPitch.x * (ballCount.x - 1.0f))) / (float)ballCount.x, (unitSize.y - (unitPadding.y * 2.0f) - (ballPitch.y * (ballCount.y - 1.0f))) / (float)ballCount.y }; if (ballSize.x > ballSize.y) { if (ballCount.x < 3) { remainsBallPitch.x = (ballSize.x - ballSize.y) * 2; } else { remainsBallPitch.x = (ballSize.x - ballSize.y) * (float)ballCount.x / ((float)ballCount.x - 1.0f); } fRadius = ballSize.y / 2; } else { if (ballCount.y < 3) { remainsBallPitch.y = (ballSize.y - ballSize.x) * 2; } else { remainsBallPitch.y = (ballSize.y - ballSize.x) * (float)ballCount.y / ((float)ballCount.y - 1.0f); } fRadius = ballSize.x / 2; } // Initialize a Ball Information's Grid int idx = 1; InitializeGrid(); // Loop (draw balls) for(INT32 nRow = 0 ; nRow < ballCount.y ; nRow++) { for(INT32 nCol = 0 ; nCol < ballCount.x ; nCol++) { // Get Radius if (_pUnitdesigninfo->IsSizeManually(nCol, nRow)) { if (!_pUnitdesigninfo->GetBallRadius(nCol, nRow, fEachRadius)) { fEachRadius = fRadius; } } else { fEachRadius = fRadius; } _pUnitdesigninfo->SetBallRadius(nCol, nRow, fEachRadius); // Get Position if (_pUnitdesigninfo->IsBallPosManually(nCol, nRow)) { if (!_pUnitdesigninfo->GetBallPoint(nCol, nRow, point)) { point.x = ballStartPoint.x + ((fRadius * 2 + ballPitch.x + remainsBallPitch.x) * nCol) + fRadius; point.y = ballStartPoint.y + ((fRadius * 2 + ballPitch.y + remainsBallPitch.y) * nRow) + fRadius; } } else { point.x = ballStartPoint.x + ((fRadius * 2 + ballPitch.x + remainsBallPitch.x) * nCol) + fRadius; point.y = ballStartPoint.y + ((fRadius * 2 + ballPitch.y + remainsBallPitch.y) * nRow) + fRadius; } _pUnitdesigninfo->SetBallPoint(nCol, nRow, point); // Draw a Ball Shape if ((bIsChecked = _pUnitdesigninfo->IsChecked(nCol, nRow)) == false) { _pShape = CreateCircle(_pViewUnitPainter, clDefaultOutlineColor, clDefaultSheetColor, point.x, point.y, fEachRadius); } else { _pShape = CreateCircle(_pViewUnitPainter, clCheckedOutlineColor, clCheckedSheetColor, point.x, point.y, fEachRadius); } // Insert a Ball Shape in Layer _pLayer->insert(_pShape); // Insert a Ball Info in StringGrid InsertGridInfo(idx, nCol, nRow, point, fEachRadius, _pUnitdesigninfo->IsChecked(nCol, nRow)); idx++; } // for(INT32 col = 0 ; col < nCol ; col++) } // for(INT32 row = 0 ; row < nRow ; row++) // Set a Status of Ball Information's Grid SetGridEditingStatus(); // Insert a Layer in Layers Object _layers.insert(_pLayer); }
int main() { /*----------------------------Part 1------------------------------------*/ int ysize = 342; int xsize = 546; int padding = 1; float **inImage = ImageInit(xsize, ysize); float **padImage = ImageInit(xsize + 2*padding, ysize + 2*padding); float **sobelImage = ImageInit(xsize, ysize); float **threshImage = ImageInit(xsize, ysize); OpenImage("porsche", xsize, ysize, inImage); PadImage(inImage, padImage, xsize, ysize, padding); Sobel(padImage, sobelImage, xsize + 2*padding, ysize + 2*padding); SaveImage("porsche", "_sobel", xsize, ysize, sobelImage); BinThresh(sobelImage, threshImage, xsize, ysize, 60); SaveImage("porsche", "_thresh60", xsize, ysize, threshImage); ysize = 256; xsize = 256; OpenImage("mri", xsize, ysize, inImage); PadImage(inImage, padImage, xsize, ysize, padding); Sobel(padImage, sobelImage, xsize + 2 * padding, ysize + 2 * padding); SaveImage("mri", "_sobel", xsize, ysize, sobelImage); BinThresh(sobelImage, threshImage, xsize, ysize, 50); SaveImage("mri", "_thresh50", xsize, ysize, threshImage); free(inImage); free(padImage); free(sobelImage); free(threshImage); /*----------------------------Part 2------------------------------------*/ xsize = ysize = 256; float **circImage = ImageInit(xsize, ysize); float **padCirc = ImageInit(xsize + 2 * padding, ysize + 2 * padding); float **sobelCirc = ImageInit(xsize, ysize); float **threshCirc = ImageInit(xsize, ysize); float **noiseCirc = ImageInit(xsize, ysize); float **padNoiseCirc = ImageInit(xsize + 2 * padding, ysize + 2 * padding); float **sobelNoiseCirc = ImageInit(xsize, ysize); float **noiseGaussCirc = ImageInit(xsize, ysize); float **padNoiseGaussCirc = ImageInit(xsize + 2 * padding, ysize + 2 * padding); float **sobelNoiseGaussCirc = ImageInit(xsize, ysize); float **sobelNoiseGaussThreshCirc = ImageInit(xsize, ysize); float **test = ImageInit(xsize + 2, ysize +2); int c = 256 / 2 - 1; CreateCircle(circImage, ysize, xsize, c, c, 50, 60); CreateCircle(circImage, ysize, xsize, c, c, 50, 40); CreateCircle(circImage, ysize, xsize, c, c, 50, 20); SaveImage("circles", "", xsize, ysize, circImage); PadImage(circImage, padCirc, xsize, ysize, padding); Sobel(padCirc, sobelCirc, xsize + 2 * padding, ysize + 2 * padding); SaveImage("circles", "_sobel", xsize, ysize, sobelCirc); BinThresh(sobelCirc, threshCirc, xsize, ysize, 100); SaveImage("circles", "_thresh100", xsize, ysize, threshCirc); // Noise = 10 AddUniNoise(circImage, noiseCirc, xsize, ysize, 10); SaveImage("circles", "_noise10", xsize, ysize, noiseCirc); PadImage(noiseCirc, padNoiseCirc, xsize, ysize, padding); Sobel(padNoiseCirc, sobelNoiseCirc, xsize + 2 * padding, ysize + 2 * padding); BinThresh(sobelNoiseCirc, sobelNoiseCirc, xsize, ysize, 100); SaveImage("circles", "_noise_sobel10", xsize, ysize, sobelNoiseCirc); AccuracyReport(threshCirc, sobelNoiseCirc, xsize, ysize); GaussianSmooth(padNoiseCirc, noiseGaussCirc, xsize + 2 * padding, ysize + 2 * padding); SaveImage("circles", "_noise_gauss10", xsize, ysize, noiseGaussCirc); PadImage(noiseGaussCirc, padNoiseGaussCirc, xsize, ysize, padding); Sobel(padNoiseGaussCirc, sobelNoiseGaussCirc, xsize + 2 * padding, ysize + 2 * padding); BinThresh(sobelNoiseGaussCirc, sobelNoiseGaussThreshCirc, xsize, ysize, 100); SaveImage("circles", "_noise_sobel_gauss_thresh10", xsize, ysize, sobelNoiseGaussThreshCirc); AccuracyReport(threshCirc, sobelNoiseGaussThreshCirc, xsize, ysize); // Noise = 50 AddUniNoise(circImage, noiseCirc, xsize, ysize, 50); SaveImage("circles", "_noise50", xsize, ysize, noiseCirc); PadImage(noiseCirc, padNoiseCirc, xsize, ysize, padding); Sobel(padNoiseCirc, sobelNoiseCirc, xsize + 2 * padding, ysize + 2 * padding); BinThresh(sobelNoiseCirc, sobelNoiseCirc, xsize, ysize, 100); SaveImage("circles", "_noise_sobel50", xsize, ysize, sobelNoiseCirc); AccuracyReport(threshCirc, sobelNoiseCirc, xsize, ysize); GaussianSmooth(padNoiseCirc, noiseGaussCirc, xsize + 2 * padding, ysize + 2 * padding); SaveImage("circles", "_noise_gauss50", xsize, ysize, noiseGaussCirc); PadImage(noiseGaussCirc, padNoiseGaussCirc, xsize, ysize, padding); Sobel(padNoiseGaussCirc, sobelNoiseGaussCirc, xsize + 2 * padding, ysize + 2 * padding); BinThresh(sobelNoiseGaussCirc, sobelNoiseGaussThreshCirc, xsize, ysize, 100); SaveImage("circles", "_noise_sobel_gauss_thresh50", xsize, ysize, sobelNoiseGaussThreshCirc); AccuracyReport(threshCirc, sobelNoiseGaussThreshCirc, xsize, ysize); // Noise = 100 AddUniNoise(circImage, noiseCirc, xsize, ysize, 100); SaveImage("circles", "_noise100", xsize, ysize, noiseCirc); PadImage(noiseCirc, padNoiseCirc, xsize, ysize, padding); Sobel(padNoiseCirc, sobelNoiseCirc, xsize + 2 * padding, ysize + 2 * padding); BinThresh(sobelNoiseCirc, sobelNoiseCirc, xsize, ysize, 100); SaveImage("circles", "_noise_sobel100", xsize, ysize, sobelNoiseCirc); AccuracyReport(threshCirc, sobelNoiseCirc, xsize, ysize); GaussianSmooth(padNoiseCirc, noiseGaussCirc, xsize + 2 * padding, ysize + 2 * padding); SaveImage("circles", "_noise_gauss100", xsize, ysize, noiseGaussCirc); PadImage(noiseGaussCirc, padNoiseGaussCirc, xsize, ysize, padding); Sobel(padNoiseGaussCirc, sobelNoiseGaussCirc, xsize + 2 * padding, ysize + 2 * padding); BinThresh(sobelNoiseGaussCirc, sobelNoiseGaussThreshCirc, xsize, ysize, 100); SaveImage("circles", "_noise_sobel_gauss_thresh100", xsize, ysize, sobelNoiseGaussThreshCirc); AccuracyReport(threshCirc, sobelNoiseGaussThreshCirc, xsize, ysize); free(circImage); free(padCirc); free(sobelCirc); free(threshCirc); free(noiseCirc); free(padNoiseCirc); free(sobelNoiseCirc); free(noiseGaussCirc); free(padNoiseGaussCirc); free(sobelNoiseGaussCirc); free(sobelNoiseGaussThreshCirc); return 0; }