我有一个不均匀的网格作为二维空间中节点的坐标网格的节点存储在一个一维向量中,其中编号是自下而上,从左到右
我还得到了一条多边形单调线(图中用蓝色表示),需要从中获得一条穿过网格节点的折线(图中用红线表示)。
多段线中的点数与生成的多段线中的点数不匹配。
有没有人有任何想法来解决这个问题?
我有结构来定义一个点:
struct point_d
{
double x;
double y;
};
和
struct point_f
{
float x;
float y;
};
并且有一个将点数组写入文件的方法,该方法是静态的并且在 export_to_file 类中。
h文件中的方法描述:
template<typename T>
static void save_to_bln_contour(deque<T> points, const int type_contour, const string filename);
cpp文件中的方法:
template<typename T>
export_to_file::save_to_bln_contour(deque<T> points, const int type_contour, const string filename)
{
/**/
}
我这样调用方法:
export_to_file::save_to_bln_contour<point_d>(points, 1, "test1");
如果此方法包含在我调用它的同一类中,则没有错误。怎么了?
如果我按上述方式编写,那么工作室链接器会发誓错误代码 LNK2019:
"public: static void __cdecl export_to_file::save_to_bln_contour(class std::deque >,int,class std::basic_string,class std::allocator >)" (?? $save_to_bln_contour@Upoint_d@@@export_to_file@@SAXV?$ deque@Upoint_d@@V?$allocator@Upoint_d@@@std@@@std@@HV?$basic_string@DU?$char_traits@D@std@@V ?$allocator@D@2@@2@@Z ) 和 "public: void __cdecl surface_fault::get_points_intersect(class surface_res &,class fault *)" (?get_points_intersect@surface_fault@@QEAAXAEAVsurface_res@@PEAVfault@@@Z) GRD_MBA E:\Projects\GRD_MBA\GRD_MBA\surface_fault.obj 1
工作室中的编码存在问题。
我需要为 point_d 结构和 point_f 结构的点调用save_to_bln_contour方法。
我在c#中有这样的方法:
public double[] GetCoordinates(Func<Point3D, double> func)
{
var values = new List<double>();
foreach (var p in _points)
{
values.Add(func(p));
}
return values.ToArray();
}
我可以这样称呼它:
GetCoordinates(d => d.X)
GetCoordinates(d => d.Y)
GetCoordinates(d => d.Z)
此方法允许您“拉出”不同的数组,具体取决于调用方法时指定的函数。
_points 是 Point3D 结构的列表,Point3D 结构包含三个字段 double x、double y、double z。
该方法是为了结合三种方法而编写的:
public List<double> GetPointsX()
{
List<double> x = new List<double> ();
foreach (var p in _points)
{
x.Add(p.X);
}
return x;
}
public List<double> GetPointsY()
{
List<double> y = new List<double> ();
foreach (var p in _points)
{
y.Add(p.Y);
}
return y;
}
public List<double> GetPointsZ()
{
List<double> z = new List<double> ();
foreach (var p in _points)
{
z.Add(p.Z);
}
return z;
}
本质上执行相同的操作 - 从 Point3D 结构列表返回 x、y、z 的单个值列表
这种组合方法可以用c++重写吗?也许 C++ 中有 Func 委托的类似物?
如何从中间数组中正确释放内存?例如,让我们有以下方法:
void Calc(int** & A)
{
int * B = new int[_countI * _countJ];
/*какие-то вычисления с участием массива B*/
/*перевод одномерного массива B в двумерный массив A*/
int k = 0;
for (int i = 0; i < _countI; i++)
{
for (int j = 0; j < _countJ; j++)
{
A[i][j] = B[k];
k++;
}
}
}
如何在此方法中进一步从数组 B 中释放内存?如果我写delete[] B;
,那么数组 A 会发生什么?
我需要为 youtrack 创建一个请求,但有以下计划的例外: Artist: I #Incomplete #Exception Status: {For testing}。如何使用这个“异常”标签?那些。我需要排除处于测试阶段的任务。
我有一个这样的段对象列表:
public Class Line
{
public int Type;
public float From;
public float To;
}
type 字段可以是 2 或 3,如果是 2,则需要合并段,如果是 3,则从所有先前的段中减去当前段。
例如,让我们有一个包含以下元素的列表:
列表中元素的顺序很重要。
在结果列表中,我需要获取以下列表:
那些。重点是:我正在遍历原始列表,找到当前元素和结果列表的元素之间的共同点。如果结果列表为空,那么我将当前元素添加到那里,如果那里有元素,那么,根据段的类型,我需要将它与结果列表中的所有内容组合起来,或者从所有元素中减去当前元素结果列表的元素。
以这种形式表示初始和结果段列表对我来说更方便:
在垂直实线后面,我形成了最终版本
提交一个想法来解决这个问题。欢迎任何帮助。
请帮助算法。我有一个这样的列表:
public class Stratigraphy
{
public Stratigraphy(int idType, int idSysstratigraphy, int stratparent, string name, string nameAdd, int ordernum)
{
IdType = idType;
IdSysstratigraphy = idSysstratigraphy;
Stratparent = stratparent;
Ordernum = ordernum;
}
public int IdType { get; set; }
public int IdSysstratigraphy { get; set; }
public int Stratparent { get; set; }
public int Ordernum { get; set; }
}
看起来,例如,像这样:
这里的 IdType 是主要排序的字段。StratParent 父元素是指 IdSysstratigraphy。OrderNum 元素顺序 i common StratParent
如何根据给定的列表想到一种算法来显示这样的结构?
我有一个来自 UITypeEditor 的小类,我需要它以便在 PropertyGrid 中为集合属性创建一个带有复选标记的下拉列表。例如,我在杂货清单中创建了一个产品类别(水果、蔬菜),并且有一个所有产品的列表,我需要在其中选择属于该特定类别的产品。那些。我在空产品列表中添加了一个新类别“水果”,对于这个类别,我从属于它的产品的全局列表中选择:“苹果”、“梨”、“香蕉”。接下来,我想创建另一个类别,例如“蔬菜”,然后再次从全局列表中选择一些蔬菜。问题在于,在创建最后一个类别后,所有其他类别都会获得与最后一个类别相同的产品集。这是代码:
public class CheckedListBoxUiTypeEditor : UITypeEditor
{
private readonly CheckedListBox _checklisbox1 = new CheckedListBox();
private IWindowsFormsEditorService _es;
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.DropDown;
}
public override bool IsDropDownResizable => true;
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
if (provider != null)
{
_es = provider.GetService(typeof (IWindowsFormsEditorService)) as IWindowsFormsEditorService;
}
if (_es != null)
{
LoadValues(value);
_es.DropDownControl(_checklisbox1);
}
_result.Clear();
foreach (string str in _checklisbox1.CheckedItems)
{
_result.Add(str);
}
return _result;
}
private readonly List<string> _defaultList = FormLas.ListAll;
private readonly List<string> _result = new List<string>();
private void LoadValues(object value)
{
Hashtable table = new Hashtable();
foreach (string str in _defaultList)
{
table.Add(str, false);
}
_checklisbox1.Items.Clear();
foreach (DictionaryEntry dic in table)
{
_checklisbox1.Items.Add(dic.Key, (bool) dic.Value);
}
if (((List<string>) value).Count > 0)
{
foreach (string str in (List<string>)value)
{
for (int i = 0; i < _checklisbox1.Items.Count; i++)
{
if (str == _checklisbox1.Items[i])
{
_checklisbox1.SetItemChecked(i, true);
}
}
}
}
}
}