|
degate 0.1.1
|
00001 /* -*-c++-*- 00002 00003 This file is part of the IC reverse engineering tool degate. 00004 00005 Copyright 2008, 2009, 2010 by Martin Schobert 00006 00007 Degate is free software: you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation, either version 3 of the License, or 00010 any later version. 00011 00012 Degate is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with degate. If not, see <http://www.gnu.org/licenses/>. 00019 00020 */ 00021 00022 #include <WireMatching.h> 00023 #include <ZeroCrossingEdgeDetection.h> 00024 #include <BoundingBox.h> 00025 #include <LineSegmentExtraction.h> 00026 #include <MedianFilter.h> 00027 #include <boost/foreach.hpp> 00028 00029 using namespace degate; 00030 00031 WireMatching::WireMatching() : 00032 wire_diameter(5), 00033 median_filter_width(3), 00034 sigma(0.5), 00035 min_edge_magnitude(0.25) { 00036 } 00037 00038 00039 void WireMatching::init(BoundingBox const& bounding_box, Project_shptr project) { 00040 00041 this->bounding_box = bounding_box; 00042 00043 if(project == NULL) 00044 throw InvalidPointerException("Invalid pointer for parameter project."); 00045 00046 lmodel = project->get_logic_model(); 00047 assert(lmodel != NULL); // always has a logic model 00048 00049 layer = lmodel->get_current_layer(); 00050 if(layer == NULL) throw DegateRuntimeException("No current layer in project."); 00051 00052 00053 ScalingManager_shptr sm = layer->get_scaling_manager(); 00054 assert(sm != NULL); 00055 00056 img = sm->get_image(1).second; 00057 assert(img != NULL); 00058 } 00059 00060 00061 void WireMatching::set_wire_diameter(unsigned int wire_diameter) { 00062 this->wire_diameter = wire_diameter; 00063 } 00064 00065 void WireMatching::set_median_filter_width(unsigned int median_filter_width) { 00066 this->median_filter_width = median_filter_width; 00067 } 00068 00069 void WireMatching::set_sigma(double sigma) { 00070 this->sigma = sigma; 00071 } 00072 00073 void WireMatching::set_min_edge_magnitude(double min_edge_magnitude) { 00074 this->min_edge_magnitude = min_edge_magnitude; 00075 } 00076 00077 void WireMatching::run() { 00078 00079 ZeroCrossingEdgeDetection ed(bounding_box.get_min_x(), 00080 bounding_box.get_max_x(), 00081 bounding_box.get_min_y(), 00082 bounding_box.get_max_y(), 00083 median_filter_width, 00084 sigma > 0 ? 10 : 0, 00085 sigma, 00086 wire_diameter >> 1, 00087 wire_diameter + (wire_diameter >> 1), 00088 min_edge_magnitude, 0.5); 00089 00090 TileImage_GS_DOUBLE_shptr i = ed.run(img, TileImage_GS_DOUBLE_shptr(), "/tmp"); 00091 assert(i != NULL); 00092 00093 LineSegmentExtraction<TileImage_GS_DOUBLE> extraction(i, wire_diameter/2, 2, ed.get_border()); 00094 LineSegmentMap_shptr line_segments = extraction.run(); 00095 assert(line_segments != NULL); 00096 00097 assert(lmodel != NULL); 00098 assert(layer != NULL); 00099 00100 BOOST_FOREACH(LineSegment_shptr ls, *line_segments) { 00101 debug(TM, "found wire"); 00102 Wire_shptr w(new Wire(bounding_box.get_min_x() + ls->get_from_x(), 00103 bounding_box.get_min_y() + ls->get_from_y(), 00104 bounding_box.get_min_x() + ls->get_to_x(), 00105 bounding_box.get_min_y() + ls->get_to_y(), 00106 wire_diameter)); 00107 00108 lmodel->add_object(layer->get_layer_pos(), w); 00109 } 00110 00111 } 00112
1.7.4