MCPcopy Create free account
hub / github.com/SimVascular/SimVascular / PyImageNew

Function PyImageNew

Code/Source/PythonAPI/ImagingImage_PyClass.cxx:1138–1179  ·  view source on GitHub ↗

------------ PyImageNew ------------ Object creation function, equivalent to the Python __new__() method. The generic handler creates a new instance using the tp_alloc field.

Source from the content-addressed store, hash-verified

1136// The generic handler creates a new instance using the tp_alloc field.
1137//
1138static PyObject *
1139PyImageNew(PyTypeObject *type, PyObject *args, PyObject *kwargs)
1140{
1141 static char *keywords[] = {"file_name", "scale_factor", NULL};
1142 auto api = PyUtilApiFunction("|sO!", PyRunTimeErr, "imaging.Image");
1143 char* fileNameArg = nullptr;
1144 PyObject* scaleObj = nullptr;
1145
1146 if (!PyArg_ParseTupleAndKeywords(args, kwargs, api.format, keywords, &fileNameArg, &PyFloat_Type, &scaleObj)) {
1147 return api.argsError();
1148 }
1149
1150 std::cout << "[PyImageNew] PyImageNew " << std::endl;
1151 auto self = (PyImage*)type->tp_alloc(type, 0);
1152 if (self != NULL) {
1153 self->id = 1;
1154 }
1155
1156 if (fileNameArg != nullptr) {
1157 std::cout << "[PyImageNew] fileNameArg: " << fileNameArg << std::endl;
1158 self->image_node = ReadFile(std::string(fileNameArg));
1159 self->image_data = dynamic_cast<mitk::Image*>(self->image_node->GetData());
1160 }
1161
1162 // Process 'scale' argument.
1163 if (scaleObj != nullptr) {
1164 double scale = PyFloat_AsDouble(scaleObj);
1165 if (PyErr_Occurred()) {
1166 return nullptr;
1167 }
1168
1169 if (scale <= 0.0) {
1170 api.error("The 'scale ' argument must be >= 0.0.");
1171 return nullptr;
1172 }
1173
1174 std::cout << "[PyImageNew] Scale image: " << scale << std::endl;
1175 ScaleImage(self, scale);
1176 }
1177
1178 return (PyObject*)self;
1179}
1180
1181//----------------
1182// PyImageDealloc

Callers

nothing calls this directly

Calls 5

ScaleImageFunction · 0.85
argsErrorMethod · 0.80
errorMethod · 0.80
ReadFileFunction · 0.70
GetDataMethod · 0.45

Tested by

no test coverage detected