/****************************************************************************
** Copyright (C) 2001-2013 RibbonSoft, GmbH. All rights reserved.
**
** This file is part of the dxflib project.
**
** This file is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** Licensees holding valid dxflib Professional Edition licenses may use
** this file in accordance with the dxflib Commercial License
** Agreement provided with the Software.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.ribbonsoft.com for further details.
**
** Contact info@ribbonsoft.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#include "dl_dxf.h"
#include <algorithm>
#include <string>
#include <cstdio>
#include <cassert>
#include <cmath>
#include "dl_attributes.h"
#include "dl_codes.h"
#include "dl_creationadapter.h"
#include "dl_writer_ascii.h"
#include "iostream"
/**
* Default constructor.
*/
DL_Dxf::DL_Dxf() {
m_version = DL_VERSION_2000;
m_vertices = NULL;
m_maxVertices = 0;
m_vertexIndex = 0;
m_knots = NULL;
m_maxKnots = 0;
m_knotIndex = 0;
m_weights = NULL;
m_weightIndex = 0;
m_controlPoints = NULL;
m_maxControlPoints = 0;
m_controlPointIndex = 0;
m_fitPoints = NULL;
m_maxFitPoints = 0;
m_fitPointIndex = 0;
m_leaderVertices = NULL;
m_maxLeaderVertices = 0;
m_leaderVertexIndex = 0;
}
/**
* Destructor.
*/
DL_Dxf::~DL_Dxf() {
if (m_vertices!=NULL) {
delete[] m_vertices;
}
if (m_knots!=NULL) {
delete[] m_knots;
}
if (m_controlPoints!=NULL) {
delete[] m_controlPoints;
}
if (m_fitPoints!=NULL) {
delete[] m_fitPoints;
}
if (m_weights!=NULL) {
delete[] m_weights;
}
if (m_leaderVertices!=NULL) {
delete[] m_leaderVertices;
}
}
/**
* @brief Reads the given file and calls the appropriate functions in
* the given creation interface for every entity found in the file.
*
* @param file Input
* Path and name of file to read
* @param creationInterface
* Pointer to the class which takes care of the entities in the file.
*
* @retval true If \p file could be opened.
* @retval false If \p file could not be opened.
*/
bool DL_Dxf::in(const std::string& file, DL_CreationInterface* creationInterface) {
FILE *fp;
m_firstCall = true;
m_currentObjectType = DL_UNKNOWN;
fopen_s(&fp, file.c_str(), "rt");
if (fp) {
while (readDxfGroups(fp, creationInterface)) {}
fclose(fp);
return true;
}
return false;
}
/**
* Reads a DXF file from an existing stream.
*
* @param stream The string stream.
* @param creationInterface
* Pointer to the class which takes care of the entities in the file.
*
* @retval true If \p file could be opened.
* @retval false If \p file could not be opened.
*/
bool DL_Dxf::in(std::stringstream& stream,
DL_CreationInterface* creationInterface) {
if (stream.good()) {
m_firstCall=true;
m_currentObjectType = DL_UNKNOWN;
while (readDxfGroups(stream, creationInterface)) {}
return true;
}
return false;
}
/**
* @brief Reads a group couplet from a DXF file. Calls another function
* to process it.
*
* A group couplet consists of two lines that represent a single
* piece of data. An integer constant on the first line indicates
* the type of data. The value is on the next line.\n
*
* This function reads a couplet, determines the type of data, and
* passes the value to the the appropriate handler function of
* \p creationInterface.\n
*
* \p fp is advanced so that the next call to \p readDXFGroups() reads
* the next couplet in the file.
*
* @param fp Handle of input file
* @param creationInterface Handle of class which processes entities
* in the file
*
* @retval true If EOF not reached.
* @retval false If EOF reached.
*/
bool DL_Dxf::readDxfGroups(FILE *fp, DL_CreationInterface* creationInterface) {
static int line = 1;
// Read one group of the DXF file and strip the lines:
if (DL_Dxf::getStrippedLine(m_groupCodeTmp, DL_DXF_MAXLINE, fp) &&
DL_Dxf::getStrippedLine(m_groupValue, DL_DXF_MAXLINE, fp, false) ) {
m_groupCode = (unsigned int)toInt(m_groupCodeTmp);
//creationInterface->processCodeValuePair(groupCode, groupValue);
line+=2;
processDXFGroup(creationInterface, m_groupCode, m_groupValue);
}
return !feof(fp);
}
/**
* Same as above but for stringstreams.
*/
bool DL_Dxf::readDxfGroups(std::stringstream& stream,
DL_CreationInterface* creationInterface) {
static int line = 1;
// Read one group of the DXF file and chop the lines:
if (DL_Dxf::getStrippedLine(m_groupCodeTmp, DL_DXF_MAXLINE, stream) &&
DL_Dxf::getStrippedLine(m_groupValue, DL_DXF_MAXLINE, stream, false) ) {
m_groupCode = (unsigned int)toInt(m_groupCodeTmp);
line+=2;
processDXFGroup(creationInterface, m_groupCode, m_groupValue);
}
return !stream.eof();
}
/**
* @brief Reads line from file & strips whitespace at start and newline
* at end.
*
* @param s Output\n
* Pointer to character array that chopped line will be returned in.
* @param size Size of \p s. (Including space for NULL.)
* @param fp Input\n
* Handle of input file.
*
* @retval true if line could be read
* @retval false if \p fp is already at end of file
*
* @todo Change function to use safer FreeBSD strl* functions
* @todo Is it a problem if line is blank (i.e., newline only)?
* Then, when function returns, (s==NULL).
*/
bool DL_Dxf::getStrippedLine(std::string& s, unsigned int size, FILE *fp, bool stripSpace) {
if (!feof(fp)) {
// The whole line in the file. Includes space for NULL.
char* wholeLine = new char[size];
// Only the useful part of the line
char* line;
line = fgets(wholeLine, size, fp);
if (line!=NULL && line[0] != '\0') { // Evaluates to fgets() retval
// line == wholeLine at this point.
// Both guaranteed to be NULL terminated.
// Strip leading whitespace and trailing CR/LF.
stripWhiteSpace(&line, stripSpace);
s = line;
assert(size > s.length());
}
delete[] wholeLine; // Done with wholeLine
return true;
} else {
s = "";
return false;
}
}
/**
* Same as above but for stringstreams.
*/
bool DL_Dxf::getStrippedLine(std::string &s, unsigned int size,
std::stringstream& stream, bool stripSpace) {
if (!stream.eof()) {
// Only the useful part of the line
char* line = new char[size+1];
char* oriLine = line;
stream.getline(line, size);
stripWhiteSpace(&line, stripSpace);
s = line;
assert(size > s.length());
delete[] oriLine;
return true;
} else {
s[0] = '\0';
return false;
}
}
/**
* @brief Strips leading whitespace and trailing Carriage Return (CR)
* and Line Feed (LF) from NULL terminated string.
*
* @param s Input and output.
* NULL terminates string.
*
* @retval true if \p s is non-NULL
* @retval false if \p s is NULL
*/
bool DL_Dxf::stripWhiteSpace(char** s, bool stripSpace) {
// last non-NULL char:
int lastChar = strlen(*s) - 1;
// Is last character CR or LF?
while ( (lastChar >= 0) &&
(((*s)[lastChar] == 10) || ((*s)[lastChar] == 13) ||
(stripSpace && ((*s)[lastChar] == ' ' || ((*s)[lastChar] == '\t')))) ) {
(*s)[lastChar] = '\
没有合适的资源?快使用搜索试试~ 我知道了~
dxf图纸的C++解析并进行opencv绘制图
共398个文件
hpp:114个
h:97个
dxf:33个
需积分: 3 16 下载量 110 浏览量
2023-05-30
17:12:44
上传
评论 1
收藏 26.76MB ZIP 举报
温馨提示
dxf图纸的C++解析并进行opencv绘制图
资源推荐
资源详情
资源评论
收起资源包目录
dxf图纸的C++解析并进行opencv绘制图 (398个子文件)
OpenCVConfig.cmake 16KB
OpenCVModules.cmake 3KB
OpenCVModules-release.cmake 984B
OpenCVModules-debug.cmake 976B
dl_dxf.cpp 139KB
dl_dxf.cpp 139KB
dl_dxf.cpp 139KB
main0901.cpp 30KB
main.cpp 29KB
main.cpp 29KB
main0902.cpp 28KB
main.cpp 28KB
DXF2PLY.cpp 24KB
main.cpp 22KB
DXF2IMG.cpp 18KB
test_creationclass.cpp 6KB
test_creationclass.cpp 5KB
test_creationclass.cpp 5KB
dl_writer_ascii.cpp 3KB
dl_writer_ascii.cpp 3KB
dl_writer_ascii.cpp 3KB
test_matchmagnet.cpp 2KB
main.cpp 1KB
test_dxf2img.cpp 1KB
opencv_world310d.dll 65MB
ReadDXF.dll 645KB
170.dxf 185KB
demo1.dxf 148KB
demo.dxf 99KB
1.dxf 19KB
11596164.dxf 18KB
11596164.dxf 18KB
11710698.dxf 18KB
11710698.dxf 18KB
11596155.dxf 18KB
11596155.dxf 18KB
11353084.dxf 18KB
11353084.dxf 18KB
11018316.dxf 17KB
11750637.dxf 17KB
11750637.dxf 17KB
11015400.dxf 17KB
11353088.dxf 17KB
11353088.dxf 17KB
11596157.dxf 17KB
11596157.dxf 17KB
11761877.dxf 17KB
11761878.dxf 17KB
11761878.dxf 17KB
11019330.dxf 17KB
11019330.dxf 17KB
10338183.dxf 17KB
10338182.dxf 17KB
11485584.dxf 17KB
11485592.dxf 17KB
2.dxf 17KB
11485592.dxf 17KB
11485584.dxf 17KB
myfile.dxf 7KB
test.exe 116KB
ReadDXF.exp 1KB
ReadDXF.vcxproj.filters 3KB
test.vcxproj.filters 974B
.gitattributes 2KB
.gitignore 4KB
core_c.h 127KB
types_c.h 59KB
imgproc_c.h 51KB
dl_entities.h 39KB
dl_entities.h 39KB
dl_entities.h 39KB
kmeans_index.h 36KB
videoio_c.h 34KB
dist.h 27KB
hierarchical_clustering_index.h 25KB
dl_codes.h 21KB
dl_codes.h 21KB
dl_codes.h 21KB
autotuned_index.h 20KB
kdtree_single_index.h 20KB
calib3d_c.h 20KB
kdtree_index.h 19KB
dl_dxf.h 18KB
dl_dxf.h 18KB
dl_dxf.h 18KB
lsh_table.h 18KB
types_c.h 17KB
cvdef.h 15KB
lsh_index.h 15KB
result_set.h 15KB
dl_writer.h 14KB
dl_writer.h 14KB
dl_writer.h 14KB
tracking_c.h 11KB
dl_creationinterface.h 11KB
dl_creationinterface.h 11KB
dl_creationinterface.h 11KB
index_testing.h 11KB
highgui_c.h 10KB
any.h 8KB
共 398 条
- 1
- 2
- 3
- 4
资源评论
临渊看雾凇
- 粉丝: 934
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功