当前位置: 首页 > wzjs >正文

惠州做公司网站刚刚发生 北京严重发生

惠州做公司网站,刚刚发生 北京严重发生,网页被禁用了怎么解除,欧洲vpswindows直播Open CASCADE (OCC) 是一个开源的 CAD/CAM/CAE 几何建模内核,它提供了多种容器类来存储和管理数据。下面我将详细介绍 Open CASCADE 中的主要容器类及其使用方法。 1. NCollection 容器 Open CASCADE 提供了一套名为 NCollection 的高效容器模板库,类似…

Open CASCADE (OCC) 是一个开源的 CAD/CAM/CAE 几何建模内核,它提供了多种容器类来存储和管理数据。下面我将详细介绍 Open CASCADE 中的主要容器类及其使用方法。

1. NCollection 容器

Open CASCADE 提供了一套名为 NCollection 的高效容器模板库,类似于 STL 但针对 CAD 应用进行了优化。

1.1 NCollection_Array1 - 一维数组

#include <NCollection_Array1.hxx>
#include <iostream>int main() {// 创建一个包含5个整数的数组,索引从1到5NCollection_Array1<int> arr(1, 5);// 填充数组for (int i = arr.Lower(); i <= arr.Upper(); i++) {arr(i) = i * 10;}// 访问和打印数组元素std::cout << "Array elements:" << std::endl;for (int i = arr.Lower(); i <= arr.Upper(); i++) {std::cout << "arr(" << i << ") = " << arr(i) << std::endl;}// 检查边界try {std::cout << "Attempting to access arr(0): ";std::cout << arr(0) << std::endl; // 这将抛出异常} catch (Standard_OutOfRange&) {std::cout << "Out of range exception caught!" << std::endl;}return 0;
}

1.2 NCollection_List - 双向链表

#include <NCollection_List.hxx>
#include <iostream>int main() {// 创建一个整数链表NCollection_List<int> list;// 添加元素list.Append(10);list.Append(20);list.Append(30);list.Prepend(5); // 在开头添加// 遍历链表std::cout << "List contents:" << std::endl;for (NCollection_List<int>::Iterator it(list); it.More(); it.Next()) {std::cout << it.Value() << std::endl;}// 检查是否包含某个值bool contains20 = list.Contains(20);std::cout << "List contains 20: " << (contains20 ? "true" : "false") << std::endl;// 删除元素list.Remove(20);// 再次遍历std::cout << "List after removing 20:" << std::endl;for (NCollection_List<int>::Iterator it(list); it.More(); it.Next()) {std::cout << it.Value() << std::endl;}return 0;
}

1.3 NCollection_Map - 哈希映射

#include <NCollection_Map.hxx>
#include <NCollection_DefaultHasher.hxx>
#include <iostream>int main() {// 创建一个整数到字符串的映射NCollection_Map<int, NCollection_DefaultHasher<int>> intMap;// 添加元素intMap.Add(1);intMap.Add(2);intMap.Add(3);// 检查元素是否存在std::cout << "Map contains 2: " << (intMap.Contains(2) ? "true" : "false") << std::endl;std::cout << "Map contains 5: " << (intMap.Contains(5) ? "true" : "false") << std::endl;// 遍历映射std::cout << "Map contents:" << std::endl;for (NCollection_Map<int, NCollection_DefaultHasher<int>>::Iterator it(intMap); it.More(); it.Next()) {std::cout << it.Key() << std::endl;}// 删除元素intMap.Remove(2);// 再次检查std::cout << "After removal, map contains 2: " << (intMap.Contains(2) ? "true" : "false") << std::endl;return 0;
}

1.4 NCollection_DataMap - 键值对映射

#include <NCollection_DataMap.hxx>
#include <TCollection_AsciiString.hxx>
#include <iostream>int main() {// 创建一个字符串到整数的映射NCollection_DataMap<TCollection_AsciiString, int> strToIntMap;// 添加元素strToIntMap.Bind("one", 1);strToIntMap.Bind("two", 2);strToIntMap.Bind("three", 3);// 访问元素if (strToIntMap.IsBound("two")) {std::cout << "Value for 'two': " << strToIntMap.Find("two") << std::endl;}// 遍历映射std::cout << "DataMap contents:" << std::endl;NCollection_DataMap<TCollection_AsciiString, int>::Iterator it(strToIntMap);for (; it.More(); it.Next()) {std::cout << it.Key() << " => " << it.Value() << std::endl;}// 更新值strToIntMap("two") = 22;// 检查更新std::cout << "Updated value for 'two': " << strToIntMap.Find("two") << std::endl;// 删除元素strToIntMap.UnBind("two");// 检查删除std::cout << "After removal, 'two' exists: " << (strToIntMap.IsBound("two") ? "true" : "false") << std::endl;return 0;
}

2. TCollection 容器

TCollection 是 Open CASCADE 提供的另一组容器类,主要用于字符串处理。

2.1 TColStd_Array1OfReal - 实数数组

#include <TColStd_Array1OfReal.hxx>
#include <iostream>int main() {// 创建一个实数数组,索引从0到4TColStd_Array1OfReal realArray(0, 4);// 填充数组for (int i = realArray.Lower(); i <= realArray.Upper(); i++) {realArray(i) = i * 1.5;}// 访问和打印数组元素std::cout << "Real array elements:" << std::endl;for (int i = realArray.Lower(); i <= realArray.Upper(); i++) {std::cout << "realArray(" << i << ") = " << realArray(i) << std::endl;}// 修改元素realArray(2) = 99.9;// 显示修改后的值std::cout << "Modified realArray(2) = " << realArray(2) << std::endl;return 0;
}

2.2 TColStd_SequenceOfReal - 实数序列

#include <TColStd_SequenceOfReal.hxx>
#include <iostream>int main() {// 创建一个实数序列TColStd_SequenceOfReal realSeq;// 添加元素realSeq.Append(1.1);realSeq.Append(2.2);realSeq.Append(3.3);// 在开头插入realSeq.Prepend(0.0);// 遍历序列std::cout << "Sequence contents:" << std::endl;for (int i = 1; i <= realSeq.Length(); i++) {std::cout << "realSeq(" << i << ") = " << realSeq.Value(i) << std::endl;}// 删除元素realSeq.Remove(2); // 删除第二个元素// 再次遍历std::cout << "Sequence after removal:" << std::endl;for (int i = 1; i <= realSeq.Length(); i++) {std::cout << "realSeq(" << i << ") = " << realSeq.Value(i) << std::endl;}return 0;
}

2.3 TColStd_ListOfInteger - 整数列表

#include <TColStd_ListOfInteger.hxx>
#include <iostream>int main() {// 创建一个整数列表TColStd_ListOfInteger intList;// 添加元素intList.Append(10);intList.Append(20);intList.Append(30);// 在开头插入intList.Prepend(5);// 遍历列表std::cout << "List contents:" << std::endl;TColStd_ListIteratorOfListOfInteger it(intList);for (; it.More(); it.Next()) {std::cout << it.Value() << std::endl;}// 查找元素Standard_Integer toFind = 20;if (intList.Contains(toFind)) {std::cout << "List contains " << toFind << std::endl;} else {std::cout << "List does not contain " << toFind << std::endl;}// 删除元素intList.Remove(toFind);// 再次检查std::cout << "After removal, list contains " << toFind << ": " << (intList.Contains(toFind) ? "true" : "false") << std::endl;return 0;
}

3. 几何容器

Open CASCADE 还提供了一些专门用于几何数据的容器。

3.1 TColgp_Array1OfPnt - 点数组

#include <TColgp_Array1OfPnt.hxx>
#include <gp_Pnt.hxx>
#include <iostream>int main() {// 创建一个包含3个点的数组TColgp_Array1OfPnt points(1, 3);// 填充点points.SetValue(1, gp_Pnt(0, 0, 0));points.SetValue(2, gp_Pnt(1, 0, 0));points.SetValue(3, gp_Pnt(1, 1, 0));// 访问和打印点std::cout << "Point array contents:" << std::endl;for (int i = points.Lower(); i <= points.Upper(); i++) {gp_Pnt p = points.Value(i);std::cout << "Point " << i << ": (" << p.X() << ", " << p.Y() << ", " << p.Z() << ")" << std::endl;}// 修改点points(2).SetY(2.0);// 显示修改后的点gp_Pnt modified = points.Value(2);std::cout << "Modified point 2: (" << modified.X() << ", " << modified.Y() << ", " << modified.Z() << ")" << std::endl;return 0;
}

3.2 TColGeom_Array1OfBSplineCurve - B样条曲线数组

#include <TColGeom_Array1OfBSplineCurve.hxx>
#include <Geom_BSplineCurve.hxx>
#include <TColgp_Array1OfPnt.hxx>
#include <TColStd_Array1OfReal.hxx>
#include <TColStd_Array1OfInteger.hxx>int main() {// 创建控制点TColgp_Array1OfPnt poles(1, 4);poles.SetValue(1, gp_Pnt(0, 0, 0));poles.SetValue(2, gp_Pnt(1, 1, 0));poles.SetValue(3, gp_Pnt(2, 1, 0));poles.SetValue(4, gp_Pnt(3, 0, 0));// 创建节点和重数TColStd_Array1OfReal knots(1, 2);knots.SetValue(1, 0.0);knots.SetValue(2, 1.0);TColStd_Array1OfInteger mults(1, 2);mults.SetValue(1, 4);mults.SetValue(2, 4);// 创建B样条曲线Handle(Geom_BSplineCurve) curve1 = new Geom_BSplineCurve(poles, knots, mults, 3);// 创建另一个曲线poles.SetValue(2, gp_Pnt(1, 2, 0));Handle(Geom_BSplineCurve) curve2 = new Geom_BSplineCurve(poles, knots, mults, 3);// 创建B样条曲线数组TColGeom_Array1OfBSplineCurve curves(1, 2);curves.SetValue(1, curve1);curves.SetValue(2, curve2);// 访问曲线Handle(Geom_BSplineCurve) firstCurve = curves.Value(1);gp_Pnt startPoint = firstCurve->Value(firstCurve->FirstParameter());gp_Pnt endPoint = firstCurve->Value(firstCurve->LastParameter());// 打印曲线信息std::cout << "First curve:" << std::endl;std::cout << "  Start point: (" << startPoint.X() << ", " << startPoint.Y() << ", " << startPoint.Z() << ")" << std::endl;std::cout << "  End point: (" << endPoint.X() << ", " << endPoint.Y() << ", " << endPoint.Z() << ")" << std::endl;return 0;
}

4. 高级容器操作

4.1 容器间的转换

#include <TColStd_ListOfInteger.hxx>
#include <TColStd_SequenceOfInteger.hxx>
#include <NCollection_List.hxx>
#include <iostream>int main() {// 创建一个NCollection列表NCollection_List<int> nList;nList.Append(1);nList.Append(2);nList.Append(3);// 转换为TColStd列表TColStd_ListOfInteger tList;for (NCollection_List<int>::Iterator it(nList); it.More(); it.Next()) {tList.Append(it.Value());}// 转换为序列TColStd_SequenceOfInteger seq;TColStd_ListIteratorOfListOfInteger it(tList);for (; it.More(); it.Next()) {seq.Append(it.Value());}// 打印序列内容std::cout << "Sequence converted from NCollection list:" << std::endl;for (int i = 1; i <= seq.Length(); i++) {std::cout << seq.Value(i) << " ";}std::cout << std::endl;return 0;
}

5. 性能考虑

Open CASCADE 容器与 STL 容器的选择:

  1. NCollection vs STL:

    • NCollection 针对 CAD 数据进行了优化
    • 内存管理更符合 Open CASCADE 的整体架构
    • 与 Open CASCADE 其他类集成更好
  2. 何时使用 STL:

    • 需要与标准 C++ 代码交互时
    • 需要 STL 特定算法时
    • 性能测试显示 STL 在特定场景下更优时

总结

Open CASCADE 提供了丰富的容器类,包括:

  1. NCollection 容器:通用模板容器,类似 STL 但针对 CAD 优化
  2. TCollection 容器:主要用于字符串和基本数据类型
  3. 几何专用容器:如 TColgp_Array1OfPnt 等,用于几何数据

选择容器时应考虑:

  • 数据类型和大小
  • 需要的操作(随机访问、插入、删除等)
  • 性能要求
  • 与其他 Open CASCADE 类的互操作性

以上代码示例展示了各种容器的创建、填充、访问、修改和遍历操作,涵盖了 Open CASCADE 容器的主要功能。

http://www.dtcms.com/wzjs/27692.html

相关文章:

  • 商城网站建设方案书百度建站
  • 建设项目环境影响登记网站湖北电脑上突然出现windows优化大师
  • 武汉网站建设推广东莞seo建站如何推广
  • 温州专业微网站制作报价免费下载优化大师
  • 网站开发html文件规范网络营销就业方向和前景
  • 建设网站 (公司)西安网站制作价格
  • 网站如何换空间chrome官方下载
  • django做网站比较容易广州网络推广平台
  • 做网站建设跑业务seo网络优化师就业前景
  • 超值的扬中网站建设站长工具关键词
  • 企业综合查询网站免费下载百度seo
  • 自己怎么个人网站html网页模板
  • 枣阳网站定制百度小说排行榜2021
  • 辽源网站建设公司足球积分排行榜最新
  • 网站建设设计规范方案千部小黄油资源百度云
  • 网站服务器建立外贸接单平台
  • 供应优惠的网站网页归档深圳市龙华区
  • 做网站,就上凡科建站站长统计网站
  • icp备案网站注册自己的网站
  • 顺德网站优化公司如何推广小程序
  • 网站正在建设中的网页怎么做搜索引擎优化解释
  • 网页设计与网站建设奥鹏考试答案济南专业seo推广公司
  • 休闲吧网站建设东莞网络推广公司
  • centos7做网站今日热点新闻大事件
  • 个人网站可以做百度推广无锡百度正规推广
  • 网站备案后改域名百度推广投诉中心
  • 吕子乔做网站吹的语录百度网址大全
  • 网站建设的中期检查表南宁推广软件
  • 设计企业网站内容谷歌浏览器下载视频
  • 有哪些网站是做网批女装营销方式都有哪些